-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation_handler.hpp
executable file
·72 lines (53 loc) · 1.51 KB
/
animation_handler.hpp
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
#ifndef ANIMATION_HANDLER_HPP
#define ANIMATION_HANDLER_HPP
#include <SFML/Graphics.hpp>
#include <vector>
class Animation
{
public:
unsigned int startFrame;
unsigned int endFrame;
float duration;
Animation(unsigned int startFrame, unsigned int endFrame, float duration)
{
this->startFrame = startFrame;
this->endFrame = endFrame;
this->duration = duration;
}
unsigned int getLength() { return endFrame - startFrame + 1; }
};
class AnimationHandler
{
private:
/* Array of animations */
std::vector<Animation> animations;
/* Current time since the animation loop started */
float t;
int currentAnim;
public:
/* Add a new animation */
void addAnim(Animation& anim);
/* Update the current frame of animation. dt is the time since
* the update was last called (i.e. the time for one frame to be
* executed) */
void update(const float dt);
/* Change the animation, resetting t in the process */
void changeAnim(unsigned int animNum);
/* Current section of the texture that should be displayed */
sf::IntRect bounds;
/* Pixel dimensions of each individual frame */
sf::IntRect frameSize;
/* Constructor */
AnimationHandler()
{
this->t = 0.0f;
this->currentAnim = -1;
}
AnimationHandler(const sf::IntRect& frameSize)
{
this->frameSize = frameSize;
this->t = 0.0f;
this->currentAnim = -1;
}
};
#endif /* ANIMATION_HANDLER_HPP */