Increasing speed of certain on-going animations (MoveTo , RotateTo)

Hi everyone,
My game involves using vehicles to catch the opponent. Vehicles travel in a fixed path (Route). Movement is done using MoveTo and RotateTo actions. Now I plan to add power-ups to the game. One such power-up is increasing speed of the boarded vehicle for few seconds. If I had implemented movement manually in update method, then this would have been simple. But since I am using MoveTo and RotateTo actions, implementing this power-up seems to be a bit tricky. I am aware of setTimeScale method but that will speed up all animations present in the game. Is there something similar that increases/reduces speed of only selected animations?

Thanks.

Try this example:

 Speed* spd = Speed::create(MoveTo::create(10.0f, Vec2(2000,0)), 1.0f);
 spd->setSpeed(2.0f);
1 Like

Why not just increase the speed? All Actions have this.

Example from our Programmers Guide:

auto mySprite = Sprite::create("mysprite.png");

// Move a sprite to a specific location over 2 seconds.
auto moveTo = MoveTo::create(2, Vec2(50, 0));

mySprite->runAction(moveTo);

// Move a sprite 50 pixels to the right, and 0 pixels to the top over 2 seconds.
auto moveBy = MoveBy::create(2, Vec2(50, 0));

mySprite->runAction(moveBy);

http://cocos2d-x.org/docs/programmers-guide/actions/index.html

that is what I was looking for. I will mark question as Solved once I get time to implement this. Thanks.

I wanted a way to change the speed while the animation is in progress. The answer provided by sevent7 works

    Speed *action1=Speed::create(MoveTo::create(3, Vec2(100,800)), 1);
    action1->setTag(1);
    imageNewBlock->runAction(action1);

when on touch began this will boost speed double

((Speed*)imageNewBlock->getActionByTag(1))->setSpeed(2.0f);