- Surface* surface = surfaces[frame];
-
- context.draw_surface(surface, pos - Vector(x_hotspot, y_hotspot), layer, drawing_effect);
+ float excedent = frame - 0;
+ if((int)excedent < 0 || excedent >= get_frames())
+ { // last case can happen when not used reverse_animation()
+ frame = get_frames() - 1;
+ if(animation_loops > 0)
+ {
+ animation_loops--;
+ if(animation_loops == 0 && !next_action.empty())
+ {
+ set_action(next_action);
+ start_animation(-1);
+ }
+ }
+
+ if(fabsf(excedent) < get_frames())
+ frame += excedent;
+ }
+ }
+else
+ {
+ float excedent = frame - action->surfaces.size();
+ if((int)excedent >= 0)
+ {
+ frame = 0;
+ if(animation_loops > 0)
+ {
+ animation_loops--;
+ if(animation_loops == 0 && !next_action.empty())
+ {
+ set_action(next_action);
+ start_animation(-1);
+ }
+ }
+
+ if(excedent < get_frames())
+ frame += excedent;
+ }