9 ANIMTYPE_PLAY_N_TIMES = 1,
11 ANIMTYPE_BACK_FORTH = 3
19 size_t total_frames = 0;
21 animType type = animType::ANIMTYPE_NONE;
24 int frame_times_played = 0;
25 int cur_frame_index = 0;
26 float cur_frame_index_f = 0;
29 int flow_direction = 1;
31 bool finished =
false;
38 Animation(
int ix,
int iy ,
size_t f,
float s,
const std::string _type,
int _reps = 0)
45 type = _type ==
"play_n_times" ? ANIMTYPE_PLAY_N_TIMES :
46 _type ==
"back_forth" ? ANIMTYPE_BACK_FORTH :
47 _type ==
"looped" ? ANIMTYPE_LOOPED :
52 Animation(
int ix,
int iy,
size_t f,
float s,
const animType _type,
int _reps = 0)
63 void advanceFrame(
float deltaTime) {
64 unsigned short prev_frame_index = cur_frame_index;
67 case Animation::animType::ANIMTYPE_LOOPED:
68 case Animation::animType::ANIMTYPE_PLAY_N_TIMES:
69 cur_frame_index_f += speed * deltaTime;
70 cur_frame_index =
static_cast<unsigned short>(cur_frame_index_f);
74 if (prev_frame_index != cur_frame_index) {
75 frame_times_played = 1;
81 if (cur_frame_index > total_frames - 1)
84 if (reps && times_played >= reps) {
90 case Animation::animType::ANIMTYPE_BACK_FORTH:
91 if (flow_direction == 1) {
92 cur_frame_index_f += speed * deltaTime;
94 if (cur_frame_index_f > total_frames) {
95 cur_frame_index_f -= speed;
98 cur_frame_index =
static_cast<unsigned short>(cur_frame_index_f);
100 else if (flow_direction == -1) {
101 if (cur_frame_index > 0) {
102 cur_frame_index_f -= speed * deltaTime;
103 cur_frame_index =
static_cast<unsigned short>(cur_frame_index_f);
109 if (reps && times_played >= reps) {
115 if (prev_frame_index != cur_frame_index) {
116 frame_times_played = 1;
119 frame_times_played++;
123 case Animation::animType::ANIMTYPE_NONE:
128 void resetFrameIndex() {
130 cur_frame_index_f = 0;
131 frame_times_played = 0;