如何减慢cocos2dx游戏的所有动作

How to slow down the All actions of cocos2dx Game

我正在 上实现一个游戏。

现在我实现了一个 "Replay of My Game" 功能(游戏节目从头开始)

但我想以 1x、2x、3x、4x 的速度重玩我的游戏。当将速度更改为 2 倍时,所有动作(移动和旋转等)都应根据新更改的变量工作。

如何通过更改 CCAction 的一般速度来做到这一点?

我想要一个通用的解决方案。我知道变量或调度程序的解决方案, 但我想要一个通用的解决方案。

您可以使用以下代码来减慢或加快所有调度程序和操作:-

float val = 2.0; // to fast
val = 0.5; // to slow

Director->getInstance()->setTimeScale(val);

默认值为1.0;

自己写一个class像CCEaseIn

重写更新(浮动时间)。

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

代码可以改成这样:

m_pInner->update(func(time)); 

func(float time) 是改变时间的函数。例如 time/2 表示 0.5x,time*2 表示 2x。您可以保存一些参数,使函数更具适应性。