-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animation.cpp
49 lines (39 loc) · 877 Bytes
/
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
#include "Animation.h"
#include "Tool.h"
Animation::Animation(double deltaFrame) :deltaFrame(deltaFrame) {
}
Animation::~Animation() {
for (auto i : clips) {
SDL_DestroyTexture(i);
}
}
Animation* Animation::add(string path) {
SDL_Texture* img = Tool::openRescource(path);
clips.push_back(img);
clipNum++;
return this;
}
Animation* Animation::setLoop(bool isLoop) {
loop = isLoop;
return this;
}
void Animation::next() {
framCounter++;
if (framCounter < deltaFrame) return;
framCounter = 0;
currentClip = (++currentClip) % clipNum;
//cout << currentClip << endl;
if (currentClip == 0 && !loop) {
isEnd = true;
}
}
SDL_Texture* Animation::getCurrentClip() {
return clips[currentClip];
}
bool Animation::checkEnd() {
return isEnd;
}
Animation* Animation::setCurrentFrame(int index) {
currentClip = Tool::Clamp(index, 0, clipNum-1);
return this;
}