-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationController.cpp
More file actions
50 lines (42 loc) · 850 Bytes
/
Copy pathAnimationController.cpp
File metadata and controls
50 lines (42 loc) · 850 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
#include "AnimationController.hpp"
#ifndef __linux__
#include "SDL.h"
#else
#include <SDL2/SDL.h>
#endif
#include <iostream>
AnimationController::AnimationController(int w0, int h0, int rate0, int n0) {
index = 0;
offset = 0;
w = w0;
h = h0;
rate = rate0;
n = n0;
}
// Define qual animação está rodando
void AnimationController::setAnimation(int offset0, int n1) {
offset = offset0;
index = offset;
n = n1;
}
// Atualiza frame da animação atual
void AnimationController::updateFrame() {
Uint32 ticks = SDL_GetTicks();
index = offset + ((ticks / rate) % n);
}
// Get/set
int AnimationController::getN() {
return n;
}
int AnimationController::getW() {
return w;
}
int AnimationController::getH() {
return h;
}
void AnimationController::setIndex(int i) {
index = i;
}
int AnimationController::getIndex() {
return index;
}