I've been wondering, is there a feature where you can, like for my example, set the rotation of sprites depending on the direction it is going?
For example :
When i shoot the rocket upwards, it will face upwards.
when the rocket starts to fall downwards due to gravity, the rocket's sprite would also start rotating and face downwards.
Or something to simulate behaviors similar to shuttlecocks in badminton.
A:
On each step you need to store the position of the object you want to rotate and then compare that to the current position, it would look something like this:
float angle = -CC_RADIANS_TO_DEGREES(atan2f(oldPos.y-myObject.position.y, oldPos.x-myObject.position.x));
angle = angle < 0 ? angle + 360 : angle; myObject.rotation = angle - 180.0f;
// I minus 180 so that my object is facing the right direction, depending on your objects initial layout y//ou may have to plus or minus a different number.
oldPos = myObject.position;
本文介绍了一种游戏开发中实现游戏对象自动旋转的方法。通过记录物体的当前位置并与其旧位置进行对比,可以计算出物体的旋转角度,使得如火箭等游戏元素能够根据其运动方向进行动态旋转。
3862

被折叠的 条评论
为什么被折叠?



