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;




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



