cocos2d-xccaction

How to slow down the All actions of cocos2dx Game


I'm implementing a game on .

Now I implemented a "Replay of My Game" feature (Game shows from start)

But I want to replay my game at the speed of 1x , 2x , 3x , 4x. When changing speed to 2x all actions (move and rotate etc.) should work with respect to new changed variable.

How can I do that by changing the general speed of CCAction?

I want a general solution. I know the solution with variables or scheduler, but I want a general solution.


Solution

  • Write a class like CCEaseIn by yourself.

    Rewrite update(float time).

    m_pInner->update(powf(time, m_fRate)); // this is what update() like in CCEaseIn
    

    The code may be changed like this:

    m_pInner->update(func(time)); 
    

    func(float time) is the function to change the time. like time/2 which means to 0.5x, time*2 means 2x. You may save some param to make the function more adaptable.