Hi, is it possible to finish running action? By finishing I don’t mean stopping but instantly forwarding it to the end.
For example:
sprite->setPosition(0, 0);
sprite->runAction(MoveBy::create(0.5f, Vec2(100, 0));
finishActions(sprite); //some magic function
//now sprite is at (100, 0)
I have very complicated block of animations and very rarely something goes wrong and one of sprites is few pixels off. I wanted such a method to test if it’ll fix this bug.
This might be kind of tricky. There isn’t any method to do this to all actions of a Node.
You can “finish” subclasses of FiniteTimeAction by doing this:
action->step(action->getDuration());
Please keep in mind, that you can’t do this immediately after running the action. The action has to be running at least one tick before you can finish it this way.
So, you could tag the actions you want to finish and finish them like this:
auto move = MoveBy::create(5.0f, {500,0});
move->setTag(1); // tagged for finishing
sprite->runAction(move);
auto rotate = RotateBy::create(5.0f, 180);
rotate->setTag(1); // tagged for finishing
sprite->runAction(rotate);
// The TintTo action isn't tagged and won't be finished
sprite->runAction(TintTo::create(5.0f, 255, 0, 0));
// this is scheduled for demonstration purposes to make sure all actions are running...
scheduleOnce([=](float){
// MoveBy and RotateBy get finished, TintTo continues
auto taggedAction = static_cast<FiniteTimeAction*>(sprite->getActionByTag(1));
while (taggedAction) {
taggedAction->step(taggedAction->getDuration());
taggedAction->setTag(0);
taggedAction = static_cast<FiniteTimeAction*>(sprite->getActionByTag(1));
}
}, 0.1f, "finishTaggedActions");
Looks compicated. Anyway I’ve rewritten my animation and bug no longer appear so I don’t need to use this 