-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnimation.cpp
More file actions
52 lines (45 loc) · 950 Bytes
/
Animation.cpp
File metadata and controls
52 lines (45 loc) · 950 Bytes
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
#include "Animation.h"
Animation::Animation(sf::Texture _texture, std::vector<int> options, std::vector<int> extraOptions)
{
nFrames = options[0];
texture = _texture;
for (int i = 0; i < nFrames; i++)
{
frames.push_back({ options[1] + extraOptions[0] + i * options[3], options[2] + extraOptions[1], options[3] + extraOptions[2], options[4] + extraOptions[3] });
}
}
void Animation::ApplyToSprite(sf::Sprite *s)
{
s->setTexture(texture);
s->setTextureRect(frames[iFrame]);
}
void Animation::Update(float elapsed)
{
time += elapsed;
if (time >= holdTime)
{
time = 0;
ChangeFrame();
}
}
void Animation::ChangeFrame()
{
if (++iFrame >= nFrames)
{
iFrame = 0;
isEnd = true;
}
}
void Animation::LastFrame()
{
iFrame = nFrames-1;
}
bool Animation::isEnded()
{
if (isEnd)
{
isEnd = false;
return true;
}
return false;
}