From: Christoph Sommer Date: Mon, 18 Feb 2008 18:31:51 +0000 (+0000) Subject: Resolves issue 0000306: Tux' graphic won't change direction while he is growing. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4b32bef77b06f25a19d63ce7ab966b280fb18442;p=supertux.git Resolves issue 0000306: Tux' graphic won't change direction while he is growing. SVN-Revision: 5328 --- diff --git a/src/object/player.cpp b/src/object/player.cpp index df80ca074..489283e84 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -917,6 +917,7 @@ Player::draw(DrawingContext& context) /* Set Tux sprite action */ if (growing) { + sprite->set_action_continued((dir == LEFT)?"grow-left":"grow-right"); // while growing, do not change action // do_duck() will take care of cancelling growing manually // update() will take care of cancelling when growing completed diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index 0841a0641..20c11fb5b 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -75,6 +75,28 @@ Sprite::set_action(const std::string& name, int loops) frame = 0; } +void +Sprite::set_action_continued(const std::string& name) +{ + if(action && action->name == name) + return; + + SpriteData::Action* newaction = data.get_action(name); + if(!newaction) { + log_debug << "Action '" << name << "' not found." << std::endl; + return; + } + + action = newaction; + if(frame >= get_frames()) { + frame = fmodf(frame, get_frames()); + + if (animation_loops > 0) animation_loops--; + if(animation_done()) + frame = get_frames()-1; + } +} + bool Sprite::animation_done() { diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index a3edb3353..cf44de706 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -47,7 +47,10 @@ public: const Vector& size, const Vector& pos, int layer); /** Set action (or state) */ - void set_action(const std::string& act, int loops = -1); + void set_action(const std::string& name, int loops = -1); + + /** Set action (or state), but keep current frame number, loop counter, etc. */ + void set_action_continued(const std::string& name); /** Set number of animation cycles until animation stops */ void set_animation_loops(int loops = -1)