-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnimation.h
More file actions
76 lines (58 loc) · 1.34 KB
/
Animation.h
File metadata and controls
76 lines (58 loc) · 1.34 KB
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
#ifndef __ANIMATION_H__
#define __ANIMATION_H__
#include "SDL/include/SDL_rect.h"
#define MAX_FRAMES 128
//#define MAX_PTRFRAMES 128
class Animation
{
public:
float speed = 1.0f;
SDL_Rect frames[MAX_FRAMES];
//SDL_Rect* frames[MAX_PTRFRAMES];
bool repeat = true; //default animation is circular pattern
/*~Animation()
{
for (int i = 0; i < MAX_PTRFRAMES; ++i)
{
if (frames[i] != nullptr)
{
delete frames[i];
frames[i] = nullptr;
}
}
}*/
private:
//float current_frame;
//int last_frame = 0;
public:
float current_frame; //old workaround
int last_frame = 0;
bool finish = false; //to active last
void PushBack(const SDL_Rect& rect)//, bool flip = false)
{
//frames[last_frame] = new SDL_Rect; //pushback function for the dynamic frames array of rects mode
//*frames[last_frame] = rect;
//last_frame++;
frames[last_frame++] = rect;
}
SDL_Rect& GetCurrentFrame() //modified for avoid cycle animations of wanted linears anims
{
current_frame += speed;
if(current_frame >= last_frame && repeat == true)
current_frame = 0;
if (repeat)
return frames[(int)current_frame];
else if (!repeat)
{
if (current_frame >= last_frame)
{
finish = true;
return frames[(int)last_frame - 1];
}
else
return frames[(int)current_frame];
}
}
//bool ret(return finish);
};
#endif