Changed next action behavior.
[supertux.git] / lib / special / sprite.cpp
index 8fe622c..6ffea6a 100644 (file)
@@ -98,6 +98,11 @@ Sprite::init_defaults(Action* act)
 void
 Sprite::set_action(std::string act)
 {
+if(!next_action.empty() && animation_loops > 0)
+  {
+  next_action = act;
+  return;
+  }
 Actions::iterator i = actions.find(act);
 action = i->second;
 }
@@ -105,8 +110,8 @@ action = i->second;
 void
 Sprite::start_animation(int loops)
 {
-animation_loops = loops;
 reset();
+animation_loops = loops;
 }
 
 void
@@ -115,6 +120,7 @@ Sprite::reset()
 frame = 0;
 last_tick = SDL_GetTicks();
 animation_reversed = true;
+next_action.clear();
 }
 
 bool
@@ -156,7 +162,14 @@ if(animation_reversed)
     {  // last case can happen when not used reverse_animation()
     frame = get_frames() - 1;
     if(animation_loops > 0)
+      {
       animation_loops--;
+      if(animation_loops == 0)
+        {
+        set_action(next_action);
+        start_animation(-1);
+        }
+      }
 
     if(fabsf(excedent) < get_frames())
       frame += excedent;
@@ -169,7 +182,14 @@ else
     {
     frame = 0;
     if(animation_loops > 0)
+      {
       animation_loops--;
+      if(animation_loops == 0)
+        {
+        set_action(next_action);
+        start_animation(-1);
+        }
+      }
 
     if(excedent < get_frames())
       frame += excedent;
@@ -185,7 +205,8 @@ Sprite::draw(DrawingContext& context, const Vector& pos, int layer,
 
   if((int)frame >= get_frames() || (int)frame < 0)
     std::cerr << "Warning: frame out of range: " << (int)frame
-              << "/" << get_frames() << std::endl;
+              << "/" << get_frames() << " at sprite: " << get_name()
+              << "/" << get_action_name() << std::endl;
   else
     context.draw_surface(action->surfaces[(int)frame],
             pos - Vector(action->x_hotspot, action->y_hotspot), layer, drawing_effect);