From: Christoph Sommer Date: Fri, 3 Mar 2006 22:23:29 +0000 (+0000) Subject: Finite sprite animations now stop at last frame, not first. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6dd8ff98068af6c053733df6bb01ba47c8eb379e;p=supertux.git Finite sprite animations now stop at last frame, not first. Sprite::set_frame(int) crops frame numbers that are out of range. Sprite::check_animation() renamed to Sprite::animation_done(). SVN-Revision: 3069 --- diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index 78972c923..9fe4765db 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -67,7 +67,7 @@ Sprite::set_action(const std::string& name, int loops) } bool -Sprite::check_animation() +Sprite::animation_done() { return animation_loops == 0; } @@ -75,7 +75,7 @@ Sprite::check_animation() void Sprite::update() { - if(animation_loops == 0) + if(animation_done()) return; Uint32 ticks = SDL_GetTicks(); @@ -85,11 +85,11 @@ Sprite::update() frame += frame_inc; if(frame >= get_frames()) { - frame = fmodf(frame+get_frames(), get_frames()); - + frame = fmodf(frame, get_frames()); + animation_loops--; - if(animation_loops == 0) - frame = 0; + if(animation_done()) + frame = get_frames()-1; } } diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index cf5e6039b..0bcc4e79c 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -53,7 +53,7 @@ public: void stop_animation() { animation_loops = 0; } /** Check if animation is stopped or not */ - bool check_animation(); + bool animation_done(); float get_fps() const { return action->fps; } @@ -74,8 +74,10 @@ public: int get_frame() const { return (int)frame; } /** Set current frame */ - void set_frame(int frame_) - { if(frame_ > get_frames()) frame = 0; else frame = frame_; } + void set_frame(int frame) + { + this->frame = (frame % get_frames()); + } Surface* get_frame(unsigned int frame) { assert(frame < action->surfaces.size()); diff --git a/src/trigger/door.cpp b/src/trigger/door.cpp index cdb05ff94..a7eaf5598 100644 --- a/src/trigger/door.cpp +++ b/src/trigger/door.cpp @@ -75,7 +75,7 @@ void Door::update(float ) { //Check if door animation is complete - if(sprite->check_animation()) { + if(sprite->animation_done()) { sprite->set_action("normal"); GameSession::current()->respawn(target_sector, target_spawnpoint); } diff --git a/src/trigger/hatch.cpp b/src/trigger/hatch.cpp index 26286e249..f2e11a3b2 100644 --- a/src/trigger/hatch.cpp +++ b/src/trigger/hatch.cpp @@ -75,7 +75,7 @@ void Hatch::update(float ) { //Check if hatch animation is complete - if(sprite->check_animation()) { + if(sprite->animation_done()) { sprite->set_action("normal"); GameSession::current()->respawn(target_sector, target_spawnpoint); }