我得到了一个关于摆锤旋转角度的工作方程式,如下面的代码所示:
const float gravity = 9.8;
float L = 0.01;
double CurrentTime = CACurrentMediaTime();
double angle = 120 * sin(sqrt((gravity/L)*CurrentTime));
但我无法解决的问题是如何使精灵连续旋转,使其像钟摆一样动作。我只是让它在我点击运行时移动到角度的当前值,然后当它到达那个位置时它会停止。这是我试图做的,但只给出了刚才解释的结果:
[_claw runAction:[CCActionRepeatForever actionWithAction:[CCActionRotateTo actionWithDuration:3.0 angle:angle]]];
那么如何让它连续旋转到角度值,以便它来回摆动?任何帮助都非常感谢:D
答案 0 :(得分:0)
试试这个;
id rotation = [CCActionRotateTo actionWithDuration:3.0 angle:angle];
[_claw runAction:[CCActionRepeatForever actionWithAction:[CCSequence actions:rotation, [rotation reverse], nil]]];
如果找不到反向方法
id rotation = [CCActionRotateTo actionWithDuration:3.0 angle:angle];
id reverseRotation = [CCActionRotateTo actionWithDuration:3.0 angle:_claw.rotation];
[_claw runAction:[CCActionRepeatForever actionWithAction:[CCSequence actions:rotation, reverseRotation , nil]]];