9 ANIMTYPE_PLAY_N_TIMES = 1,
11 ANIMTYPE_BACK_FORTH = 3
16 size_t total_frames = 0;
18 animType type = animType::ANIMTYPE_NONE;
21 int frame_times_played = 0;
22 int cur_frame_index = 0;
23 float cur_frame_index_f = 0;
26 int flow_direction = 1;
28 bool finished =
false;
35 Animation(
int ix,
int iy ,
size_t f,
float s,
const std::string _type,
int _reps = 0)
42 type = _type ==
"play_n_times" ? ANIMTYPE_PLAY_N_TIMES :
43 _type ==
"back_forth" ? ANIMTYPE_BACK_FORTH :
44 _type ==
"looped" ? ANIMTYPE_LOOPED :
49 Animation(
int ix,
int iy,
size_t f,
float s,
const animType _type,
int _reps = 0)
60 void advanceFrame(
float deltaTime) {
61 unsigned short prev_frame_index = cur_frame_index;
64 case Animation::animType::ANIMTYPE_LOOPED:
65 case Animation::animType::ANIMTYPE_PLAY_N_TIMES:
66 cur_frame_index_f += speed * deltaTime;
67 cur_frame_index =
static_cast<unsigned short>(cur_frame_index_f);
70 if (prev_frame_index != cur_frame_index) {
71 frame_times_played = 1;
77 if (cur_frame_index > total_frames - 1)
81 if (reps && times_played >= reps) {
87 case Animation::animType::ANIMTYPE_BACK_FORTH:
88 if (flow_direction == 1) {
89 cur_frame_index_f += speed * deltaTime;
91 if (cur_frame_index_f > total_frames) {
92 cur_frame_index_f -= speed;
95 cur_frame_index =
static_cast<unsigned short>(cur_frame_index_f);
97 else if (flow_direction == -1) {
98 if (cur_frame_index > 0) {
99 cur_frame_index_f -= speed * deltaTime;
100 cur_frame_index =
static_cast<unsigned short>(cur_frame_index_f);
106 if (reps && times_played >= reps) {
112 if (prev_frame_index != cur_frame_index) {
113 frame_times_played = 1;
116 frame_times_played++;
120 case Animation::animType::ANIMTYPE_NONE:
125 void resetFrameIndex() {
127 cur_frame_index_f = 0;
128 frame_times_played = 0;