more work on the forest level
[supertux.git] / lib / special / sprite.cpp
index 18c6067..48aa325 100644 (file)
@@ -34,7 +34,9 @@ namespace SuperTux
 Sprite::Sprite(SpriteData& newdata)
   : data(newdata), frame(0), animation_loops(-1)
 {
-  action = data.actions.begin()->second;
+  action = data.get_action("normal");
+  if(!action)
+    action = data.actions.begin()->second;
   last_ticks = SDL_GetTicks();
 }
 
@@ -57,7 +59,7 @@ Sprite::set_action(std::string name, int loops)
     return;
 
   SpriteData::Action* newaction = data.get_action(name);
-  if(!action) {
+  if(!newaction) {
 #ifdef DEBUG
     std::cerr << "Action '" << name << "' not found.\n";
 #endif
@@ -72,7 +74,7 @@ Sprite::set_action(std::string name, int loops)
 bool
 Sprite::check_animation()
 {
-  return animation_loops;
+  return animation_loops == 0;
 }
 
 void
@@ -87,14 +89,12 @@ Sprite::update()
 
   frame += frame_inc;
 
-  float lastframe = frame;
-  frame = fmodf(frame+get_frames(), get_frames());
-  if(frame != lastframe) {
-    if(animation_loops > 0) {
-      animation_loops--;
-      if(animation_loops == 0)
-        frame = 0;
-    }
+  if(frame >= get_frames()) {
+    frame = fmodf(frame+get_frames(), get_frames());
+    
+    animation_loops--;
+    if(animation_loops == 0)
+      frame = 0;
   }
 }
 
@@ -146,4 +146,3 @@ Sprite::get_height() const
 
 }
 
-/* EOF */