Форум программистов, компьютерный форум, киберфорум
SFML
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.57/7: Рейтинг темы: голосов - 7, средняя оценка - 4.57
0 / 0 / 0
Регистрация: 26.06.2015
Сообщений: 15
1

Марио на SFML. Ошибка "'AnimationManager' is undefined"

01.07.2015, 20:53. Показов 1332. Ответов 6
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Всем привет! Пишу игру платформер на SFML C++.Возникла ошибка 'AnimationManager' is undefined. Здесь тексты cpp и hpp:


C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <SFML/Graphics.hpp>
 
using namespace sf;
 
int main()
{
    RenderWindow window(VideoMode(200, 200),"SFML worcs!");
 
 
    Texture q;
    q.loadFromFile("fang.png");
    AnimationManager anim;
    anim.create("walk",q,0,244,40,50,6,0.005,40);
    anim.create("jump",q,0,528,29,30,4,0.0045,38);
    anim.create("duck",q,0,436,80,20,1,0.005);
    anim.create("stay",q,0,187,42,52,3,0.002,42);
    anim.create("shoot",q,0,572,45,52,5,0.004,45);
 
    Clock clock;
 
    while (window.isOpen())
    {
        float time = clock.getElapsedTime().asMicroseconds();
        clock.restart();
 
        time = time/800;
 
        if (time > 20) time = 20;
 
 
        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
                window.close();
        }
 
        anim.set("stay");
        if (Keyboard::isKeyPressed(Keyboard::Right)) anim.set("walk");
        if (Keyboard::isKeyPressed(Keyboard::Left)) anim.set("walk");
        if (Keyboard::isKeyPressed(Keyboard::Up)) anim.set("jump");
        if (Keyboard::isKeyPressed(Keyboard::Down)) anim.set("duck");
        if (Keyboard::isKeyPressed(Keyboard::Space)) anim.set("shoot");
 
        anim.tick(time);
 
        window.clear(Color::White);
        anim.draw(window,50,100);
        window.display();
    }
    return 0;
}
 
может не правильно создал hpp класс или ошибка в текстах. hpp создавал через source fail -add-new item-header fail .h и далее назвал anim.hpp.
 
anim.hpp*
 
 
#ifndef ANIM_H
#define ANIM_H
 
#include <SFML\Graphics.hpp>
using namespace sf;
 
class Animation
{
public:
    std::vector<IntRect> frames, frames_flip;
    float currentFrame, speed;
    bool flip, isPlaying;
    Sprite sprite;
 
 
    Animation (Texture &t, int x, int y, int w, int h, int count, float Speed, int step)
    {
        speed = Speed;
        sprite.setTexture(t);
 
        currentFrame = 0;
        isPlaying=true;
        flip=false;
        for (int i=0; i<count; i++)
        {
            frames.push_back(IntRect(x+i*step, y, w, h));
            frames_flip.push_back( IntRect(x+i*step+w, y, -w, h));
        }
    }
    void tick(float time)
    {
        if (!isPlaying) return;
 
        currentFrame += speed * time;
        if (currentFrame >  frames.size())
            currentFrame -= frames.size();
        int i=currentFrame;
        sprite.setTextureRect( frames[i]);
        if (flip) sprite.setTextureRect(frames_flip[i]);
    }
};
 
class AnimationManager
{
public:
    String currentAnim;
    std::map<String, Animation> animList;
 
    AnimationManager()
    {}
    void create(String name, Texture &t, int x, int y, int w, int h, int count, float speed, int step)
    {
        animList[name] = Animation(t, x, y, w, h, count, speed, step);
        currentAnim = name;
    }
    void draw(RenderWindow &window, int x=0, int y=0)
    {
        animList[currentAnim].sprite.setPosition(x,y);
        window.draw( animList[currentAnim].sprite );
    }
 
    void set(String name) { currentAnim = name;}
 
    void flip(bool b) {animList[currentAnim].flip = b;}
 
    void tick(float time) {animList[currentAnim].tick(time);}
 
    void pause() {animList[currentAnim].isPlaying=false;}
 
    void play() {animList[currentAnim].isPlaying=true;}
};
 
#endif ANIM_H
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
01.07.2015, 20:53
Ответы с готовыми решениями:

Ошибка undefined reference при запуске программы с sfml
Всем привет! Решил попробовать данную либу (читал статейку на хабре и решил запустить простой...

Ошибка "Undefined reference" при компиляции примера на SFML в Dev-cpp
Доброго дня, форумчане. Много читал форум и вот пришло время начать писать ).. Начал изучать...

как сделать марио касался в лаки болок из него выпали грибы которые двигались за марио
как сделать марио касался в лаки болок из него выпали грибы которые двигались за марио

Sfml и undefined
Добрый день. Поставил себе sfml 2.4.2 под ubuntu,x64. Сделал все вот по этому гайду:...

6
2782 / 1935 / 570
Регистрация: 05.06.2014
Сообщений: 5,600
01.07.2015, 20:59 2
AnimationManager объявлен в anim.hpp, в main включен только SFML/Graphics.hpp. Все используемые в cpp файле классы должны быть доступны через упомянутые в начале include.
0
0 / 0 / 0
Регистрация: 26.06.2015
Сообщений: 15
01.07.2015, 21:33  [ТС] 3
Включил include anim.hpp и после появилась ошибка в строке :anim.create("duck",q,0,436,80,20,1,0.005); не хватало 8 элемента добавил 40 :anim.create("duck",q,0,436,80,20,1,0.005,40); следом следующая в классе map:
error C2512: 'Animation::Animation' : no appropriate default constructor available

1>------ Build started: Project: 3, Configuration: Debug Win32 ------
1> 3.cpp
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(37): warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(14): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(15): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(16): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(17): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(18): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(24): warning C4244: 'initializing' : conversion from 'sf::Int64' to 'float', possible loss of data
1>c:\program files\microsoft visual studio 10.0\vc\include\map(215): error C2512: 'Animation::Animation' : no appropriate default constructor available
1> c:\program files\microsoft visual studio 10.0\vc\include\map(210) : while compiling class template member function 'Animation &std::map<_Kty,_Ty>::operator [](const sf::String &)'
1> with
1> [
1> _Kty=sf::String,
1> _Ty=Animation
1> ]
1> c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(47) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1> with
1> [
1> _Kty=sf::String,
1> _Ty=Animation
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

тексты здесь
cpp:
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <SFML/Graphics.hpp>
#include "anim.hpp"
 
using namespace sf;
 
int main()
{
    RenderWindow window(VideoMode(200, 200),"SFML worcs!");
 
 
    Texture q;
    q.loadFromFile("fang.png");
    AnimationManager anim;
    anim.create("walk",q,0,244,40,50,6,0.005,40);
    anim.create("jump",q,0,528,29,30,4,0.0045,38);
    anim.create("duck",q,0,436,80,20,1,0.005,40);
    anim.create("stay",q,0,187,42,52,3,0.002,42);
    anim.create("shoot",q,0,572,45,52,5,0.004,45);
 
    Clock clock;
 
    while (window.isOpen())
    {
        float time = clock.getElapsedTime().asMicroseconds();
        clock.restart();
 
        time = time/800;
 
        if (time > 20) time = 20;
 
 
        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
                window.close();
        }
 
        anim.set("stay");
        if (Keyboard::isKeyPressed(Keyboard::Right)) anim.set("walk");
        if (Keyboard::isKeyPressed(Keyboard::Left)) anim.set("walk");
        if (Keyboard::isKeyPressed(Keyboard::Up)) anim.set("jump");
        if (Keyboard::isKeyPressed(Keyboard::Down)) anim.set("duck");
        if (Keyboard::isKeyPressed(Keyboard::Space)) anim.set("shoot");
 
        anim.tick(time);
 
        window.clear(Color::White);
        anim.draw(window,50,100);
        window.display();
    }
    return 0;
}
 
 
hpp:
 
 
#ifndef ANIM_H
#define ANIM_H
 
#include <SFML\Graphics.hpp>
using namespace sf;
 
class Animation
{
public:
    std::vector<IntRect> frames, frames_flip;
    float currentFrame, speed;
    bool flip, isPlaying;
    Sprite sprite;
 
 
    Animation (Texture &t, int x, int y, int w, int h, int count, float Speed, int step)
    {
        speed = Speed;
        sprite.setTexture(t);
 
        currentFrame = 0;
        isPlaying=true;
        flip=false;
        for (int i=0; i<count; i++)
        {
            frames.push_back(IntRect(x+i*step, y, w, h));
            frames_flip.push_back( IntRect(x+i*step+w, y, -w, h));
        }
    }
    void tick(float time)
    {
        if (!isPlaying) return;
 
        currentFrame += speed * time;
        if (currentFrame >  frames.size())
            currentFrame -= frames.size();
        int i=currentFrame;
        sprite.setTextureRect( frames[i]);
        if (flip) sprite.setTextureRect(frames_flip[i]);
    }
};
 
class AnimationManager
{
public:
    String currentAnim;
    std::map<String, Animation> animList;
 
    AnimationManager()
    {}
    void create(String name, Texture &t, int x, int y, int w, int h, int count, float speed, int step)
    {
        animList[name] = Animation(t, x, y, w, h, count, speed, step);
        currentAnim = name;
    }
    void draw(RenderWindow &window, int x=0, int y=0)
    {
        animList[currentAnim].sprite.setPosition(x,y);
        window.draw( animList[currentAnim].sprite );
    }
 
    void set(String name) { currentAnim = name;}
 
    void flip(bool b) {animList[currentAnim].flip = b;}
 
    void tick(float time) {animList[currentAnim].tick(time);}
 
    void pause() {animList[currentAnim].isPlaying=false;}
 
    void play() {animList[currentAnim].isPlaying=true;}
};
 
#endif ANIM_H
0
67 / 67 / 72
Регистрация: 10.04.2015
Сообщений: 281
01.07.2015, 21:41 4
Цитата Сообщение от surveyor2015 Посмотреть сообщение
error C2512: 'Animation::Animation' : no appropriate default constructor available
Теоретически нету дефолтного конструктора.

Может быть, проблема здесь: std::map<String, Animation> animList;
А может и нет... Недавно было такая тема, надо поискать.
0
0 / 0 / 0
Регистрация: 26.06.2015
Сообщений: 15
01.07.2015, 22:10  [ТС] 5
Включил include anim.hpp и после появилась ошибка в строке :anim.create("duck",q,0,436,80,20,1,0.005); не хватало 8 элемента добавил 40 :anim.create("duck",q,0,436,80,20,1,0.005,40); следом следующая в классе map:
error C2512: 'Animation::Animation' : no appropriate default constructor available

1>------ Build started: Project: 3, Configuration: Debug Win32 ------
1> 3.cpp
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(37): warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(14): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(15): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(16): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(17): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(18): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(24): warning C4244: 'initializing' : conversion from 'sf::Int64' to 'float', possible loss of data
1>c:\program files\microsoft visual studio 10.0\vc\include\map(215): error C2512: 'Animation::Animation' : no appropriate default constructor available
1> c:\program files\microsoft visual studio 10.0\vc\include\map(210) : while compiling class template member function 'Animation &std::map<_Kty,_Ty>::operator [](const sf::String &)'
1> with
1> [
1> _Kty=sf::String,
1> _Ty=Animation
1> ]
1> c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(47) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1> with
1> [
1> _Kty=sf::String,
1> _Ty=Animation
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
тексты здесь
cpp:
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <SFML/Graphics.hpp>
#include "anim.hpp"
 
using namespace sf;
 
int main()
{
    RenderWindow window(VideoMode(200, 200),"SFML worcs!");
 
 
    Texture q;
    q.loadFromFile("fang.png");
    AnimationManager anim;
    anim.create("walk",q,0,244,40,50,6,0.005,40);
    anim.create("jump",q,0,528,29,30,4,0.0045,38);
    anim.create("duck",q,0,436,80,20,1,0.005,40);
    anim.create("stay",q,0,187,42,52,3,0.002,42);
    anim.create("shoot",q,0,572,45,52,5,0.004,45);
 
    Clock clock;
 
    while (window.isOpen())
    {
        float time = clock.getElapsedTime().asMicroseconds();
        clock.restart();
 
        time = time/800;
 
        if (time > 20) time = 20;
Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
                window.close();
        }
 
        anim.set("stay");
        if (Keyboard::isKeyPressed(Keyboard::Right)) anim.set("walk");
        if (Keyboard::isKeyPressed(Keyboard::Left)) anim.set("walk");
        if (Keyboard::isKeyPressed(Keyboard::Up)) anim.set("jump");
        if (Keyboard::isKeyPressed(Keyboard::Down)) anim.set("duck");
        if (Keyboard::isKeyPressed(Keyboard::Space)) anim.set("shoot");
 
        anim.tick(time);
 
        window.clear(Color::White);
        anim.draw(window,50,100);
        window.display();
    }
    return 0;
}
 
 
hpp:
 
 
#ifndef ANIM_H
#define ANIM_H
 
#include <SFML\Graphics.hpp>
using namespace sf;
 
class Animation
{
public:
    std::vector<IntRect> frames, frames_flip;
    float currentFrame, speed;
    bool flip, isPlaying;
    Sprite sprite;
 
 
    Animation (Texture &t, int x, int y, int w, int h, int count, float Speed, int step)
    {
        speed = Speed;
        sprite.setTexture(t);
 
        currentFrame = 0;
        isPlaying=true;
        flip=false;
        for (int i=0; i<count; i++)
        {
            frames.push_back(IntRect(x+i*step, y, w, h));
            frames_flip.push_back( IntRect(x+i*step+w, y, -w, h));
        }
    }
    void tick(float time)
    {
        if (!isPlaying) return;
 
        currentFrame += speed * time;
        if (currentFrame >  frames.size())
            currentFrame -= frames.size();
        int i=currentFrame;
        sprite.setTextureRect( frames[i]);
        if (flip) sprite.setTextureRect(frames_flip[i]);
    }
};
 
class AnimationManager
{
public:
    String currentAnim;
    std::map<String, Animation> animList;
 
    AnimationManager()
    {}
    void create(String name, Texture &t, int x, int y, int w, int h, int count, float speed, int step)
    {
        animList[name] = Animation(t, x, y, w, h, count, speed, step);
        currentAnim = name;
    }
    void draw(RenderWindow &window, int x=0, int y=0)
    {
        animList[currentAnim].sprite.setPosition(x,y);
        window.draw( animList[currentAnim].sprite );
    }
 
    void set(String name) { currentAnim = name;}
 
    void flip(bool b) {animList[currentAnim].flip = b;}
 
    void tick(float time) {animList[currentAnim].tick(time);}
 
    void pause() {animList[currentAnim].isPlaying=false;}
 
    void play() {animList[currentAnim].isPlaying=true;}
};
 
#endif ANIM_H
0
0 / 0 / 0
Регистрация: 26.06.2015
Сообщений: 15
01.07.2015, 23:01  [ТС] 6
Включил include anim.hpp и после появилась ошибка в строке :anim.create("duck",q,0,436,80,20,1,0.005); не хватало 8 элемента добавил 40 :anim.create("duck",q,0,436,80,20,1,0.005,40); следом следующая в классе map:
error C2512: 'Animation::Animation' : no appropriate default constructor available

1>------ Build started: Project: 3, Configuration: Debug Win32 ------
1> 3.cpp
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(37): warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(14): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(15): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(16): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(17): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(18): warning C4305: 'argument' : truncation from 'double' to 'float'
1>c:\users\valentin\documents\visual studio 2010\projects\3\3\3.cpp(24): warning C4244: 'initializing' : conversion from 'sf::Int64' to 'float', possible loss of data
1>c:\program files\microsoft visual studio 10.0\vc\include\map(215): error C2512: 'Animation::Animation' : no appropriate default constructor available
1> c:\program files\microsoft visual studio 10.0\vc\include\map(210) : while compiling class template member function 'Animation &std::map<_Kty,_Ty>::operator [](const sf::String &)'
1> with
1> [
1> _Kty=sf::String,
1> _Ty=Animation
1> ]
1> c:\users\valentin\documents\visual studio 2010\projects\3\3\anim.hpp(47) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1> with
1> [
1> _Kty=sf::String,
1> _Ty=Animation
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
тексты здесь
cpp:
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <SFML/Graphics.hpp>
#include "anim.hpp"
 
using namespace sf;
 
int main()
{
    RenderWindow window(VideoMode(200, 200),"SFML worcs!");
 
 
    Texture q;
    q.loadFromFile("fang.png");
    AnimationManager anim;
    anim.create("walk",q,0,244,40,50,6,0.005,40);
    anim.create("jump",q,0,528,29,30,4,0.0045,38);
    anim.create("duck",q,0,436,80,20,1,0.005,40);
    anim.create("stay",q,0,187,42,52,3,0.002,42);
    anim.create("shoot",q,0,572,45,52,5,0.004,45);
 
    Clock clock;
 
    while (window.isOpen())
    {
        float time = clock.getElapsedTime().asMicroseconds();
        clock.restart();
 
        time = time/800;
 
        if (time > 20) time = 20;
 
 
        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
                window.close();
        }
 
        anim.set("stay");
        if (Keyboard::isKeyPressed(Keyboard::Right)) anim.set("walk");
        if (Keyboard::isKeyPressed(Keyboard::Left)) anim.set("walk");
        if (Keyboard::isKeyPressed(Keyboard::Up)) anim.set("jump");
        if (Keyboard::isKeyPressed(Keyboard::Down)) anim.set("duck");
        if (Keyboard::isKeyPressed(Keyboard::Space)) anim.set("shoot");
 
        anim.tick(time);
 
        window.clear(Color::White);
        anim.draw(window,50,100);
        window.display();
    }
    return 0;
}
hpp:

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef ANIM_H
#define ANIM_H
 
#include <SFML\Graphics.hpp>
using namespace sf;
 
class Animation
{
public:
    std::vector<IntRect> frames, frames_flip;
    float currentFrame, speed;
    bool flip, isPlaying;
    Sprite sprite;
 
 
    Animation (Texture &t, int x, int y, int w, int h, int count, float Speed, int step)
    {
        speed = Speed;
        sprite.setTexture(t);
 
        currentFrame = 0;
        isPlaying=true;
        flip=false;
        for (int i=0; i<count; i++)
        {
            frames.push_back(IntRect(x+i*step, y, w, h));
            frames_flip.push_back( IntRect(x+i*step+w, y, -w, h));
        }
    }
    void tick(float time)
    {
        if (!isPlaying) return;
 
        currentFrame += speed * time;
        if (currentFrame >  frames.size())
            currentFrame -= frames.size();
        int i=currentFrame;
        sprite.setTextureRect( frames[i]);
        if (flip) sprite.setTextureRect(frames_flip[i]);
    }
};
 
class AnimationManager
{
public:
    String currentAnim;
    std::map<String, Animation> animList;
 
    AnimationManager()
    {}
    void create(String name, Texture &t, int x, int y, int w, int h, int count, float speed, int step)
    {
        animList[name] = Animation(t, x, y, w, h, count, speed, step);
        currentAnim = name;
    }
    void draw(RenderWindow &window, int x=0, int y=0)
    {
        animList[currentAnim].sprite.setPosition(x,y);
        window.draw( animList[currentAnim].sprite );
    }
 
    void set(String name) { currentAnim = name;}
 
    void flip(bool b) {animList[currentAnim].flip = b;}
 
    void tick(float time) {animList[currentAnim].tick(time);}
 
    void pause() {animList[currentAnim].isPlaying=false;}
 
    void play() {animList[currentAnim].isPlaying=true;}
};
 
#endif ANIM_H
0
lss
941 / 869 / 355
Регистрация: 10.10.2012
Сообщений: 2,706
02.07.2015, 00:09 7
Цитата Сообщение от surveyor2015 Посмотреть сообщение
'Animation::Animation' : no appropriate default constructor available
Нет конструктора по умолчанию.
0
02.07.2015, 00:09
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
02.07.2015, 00:09
Помогаю со студенческими работами здесь

Undefined reference to в Code::Blocks [SFML]
Впервые задаю вопрос на этом форуме, да и вообще на форумах. Уже много раз читал подобные темы и...

Ошибка: CMake Error at deps/SFML/src/SFML/Window/CMakeLists.txt:106 (message): Xrandr library not found
Собсна, решил собрать библиотеку , столкнулся с непонятками, но потом дошло что не так, начал...

Ошибка C2661 с RectangleShape в Марио на C++
Код был написан по туториалу с этого видео - http://www.youtube.com/watch?v=6OHMFwQK44k. SFML...

Игра "Марио" - ошибка после компиляции
после того как подключил SFML игра скомпилировалась но выдает ошибку #include...

ошибка sfml
Здравствуйте форумчане, сразу о проблеме,скачал библиотеку sfml сделал все по инструкции dll...

SFML Ошибка с if else
При попытке повторного введения &quot;1&quot; показывает &quot;Итог 2&quot; PS Я новичок, потому не бейте...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
7
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru