-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.cpp
118 lines (99 loc) · 2.31 KB
/
animation.cpp
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
#include "animation.h"
using namespace sf;
using namespace std;
Animation::Animation()
{
}
Animation::~Animation()
{
}
int Animation::getFrameWidth()
{
//Calcule la largeur des images à afficher
return sprite.GetImage()->GetWidth() / amountOfFrameX;
}
int Animation::getFrameHeight()
{
//Calcule la hauteur des images à afficher
return sprite.GetImage()->GetHeight() / amountOfFrameY;
}
void Animation::initialize(float x, float y, int frameX, int frameY)
{
//Fait office de constructeur
frameCounter = 0;
switchFrame = 3;
this->x = x;
this->y = y;
amountOfFrameY = frameY;
amountOfFrameX = frameX;
sprite.SetPosition(x,y);
currentFrameX = currentFrameY = 0;
active = false;
}
void Animation::update(RenderWindow &app)
{
//Permet de faire défiler les images
if(active)
frameCounter += 10*(float)app.GetFrameTime();
else
frameCounter += clock.GetElapsedTime();
if(frameCounter >= switchFrame)
{
frameCounter = 0;
clock.Reset();
currentFrameX += getFrameWidth();
}
if(currentFrameX >= sprite.GetImage()->GetWidth())
currentFrameX = 0;
sprite.SetSubRect(IntRect(currentFrameX, currentFrameY*getFrameHeight(), currentFrameX + getFrameWidth(),currentFrameY*getFrameHeight() + getFrameHeight()));
sprite.SetPosition(x,y);
}
void Animation::draw(RenderWindow &app)
{
app.Draw(sprite);
}
bool Animation::getActive()
{
return active;
}
void Animation::setActive(bool value)
{
active = value;
}
int Animation::getCurrentFrame(int axis)
{
//Axe 1 : x, les autre : y
//Permet de savoir à quelle image on en est
if(axis == 1)
return currentFrameX;
else
return currentFrameY;
}
void Animation::setCurrentFrame(int axis, int value)
{
//Axe 1 : x, les autre : y
//value : Les valeurs commencent à zéro et sont croissante en descendant l'image.
if(axis == 1)
currentFrameX = value;
else
currentFrameY = value;
}
int Animation::getPosition(int axis)
{
if(axis == 1)
return x;
else
return y;
}
void Animation::setPosition(int axis, int value)
{
//Axe 1 : x, les autre : y
if(axis == 1)
x = value;
else
y = value;
}
void Animation::setImage(Image &tempImage)
{
sprite.SetImage(tempImage);
}