-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animation.cpp
executable file
·58 lines (42 loc) · 1018 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
50
51
52
53
54
55
56
57
58
#include "Animation.h"
Animation::Animation(){
currentFrame = 0;
maxFrames = 0;
frameInc = 1;
frameRate = 100; //milliseconds
oldTime = 0;
oscilate = false;
}
void Animation::animate(){
if (oldTime + frameRate > SDL_GetTicks()){
return;
}
oldTime = SDL_GetTicks();
currentFrame += frameInc;
if(oscilate){
if(frameInc > 0){
if(currentFrame >= maxFrames){
frameInc = -frameInc;
}
} else{
if(currentFrame <= 0){
frameInc = -frameInc;
}
}
} else {
if(currentFrame >= maxFrames){
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;
}