-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnimation.hpp
90 lines (54 loc) · 1.38 KB
/
Animation.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#ifndef Animation_hpp
#define Animation_hpp
#include <vector>
#include <functional>
#include <map>
#include "Bitmask.hpp"
using AnimationAction = std::function<void(void)>;
struct FrameData
{
int id; // Texture id (retrieved from our texture allocator).
int x; // x position of sprite in the texture.
int y; // y position of sprite in the texture.
int width; // Width of sprite.
int height; // Height of sprite.
float displayTimeSeconds; // How long to display the frame.
};
enum class FacingDirection
{
None,
Left,
Right,
Up,
Down
};
class Animation
{
public:
Animation();
void AddFrame(int textureID, int x, int y,
int width, int height, float frameTime, bool looped);
const FrameData* GetCurrentFrame() const;
bool UpdateFrame(float deltaTime);
void Reset();
void AddFrameAction(unsigned int frame, AnimationAction action);
void SetLooped(bool looped);
bool IsLooped();
bool IsFinished();
private:
void IncrementFrame();
// Stores all frames for our animation.
std::vector<FrameData> frames;
// Current frame.
int currentFrameIndex;
// We use this to decide when to transition to the next frame.
float currentFrameTime;
bool releaseFirstFrame;
//animation actions
std::map<int, std::vector<AnimationAction>> actions;
void RunActionForCurrentFrame();
Bitmask framesWithActions;
bool isLooped;
};
#endif /* Animation_hpp */