-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.cpp
More file actions
62 lines (43 loc) · 932 Bytes
/
Animation.cpp
File metadata and controls
62 lines (43 loc) · 932 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
53
54
55
56
57
58
59
60
61
62
#include "Animation.h"
Animation::Animation() {
currentFrame = 0;
maxFrames = 0;
frameInc = 1;
frameRate = 100; //Milliseconds
oldTime = 0;
oscillate = false;
}
Animation::~Animation() {
}
void Animation::onTick() {
if(oldTime + frameRate > SDL_GetTicks()) {
return;
}
oldTime = SDL_GetTicks();
currentFrame += frameInc;
if(oscillate) {
if(frameInc > 0) {
if(currentFrame >= maxFrames - 1) {
frameInc = -frameInc;
}
}else{
if(currentFrame <= 0) {
frameInc = -frameInc;
}
}
}else{
if(currentFrame >= maxFrames - 1) {
currentFrame = 0;
}
}
}
void Animation::setFrameRate(int rate) {
frameRate = rate;
}
void Animation::setCurrentFrame(int frame) {
if(frame < 0 || frame >= maxFrames) return;
currentFrame = frame;
}
int Animation::getCurrentFrame() {
return currentFrame;
}