/* 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
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()
{
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)