ios - Animate rotation of SKSpriteNode -
i attempting rotate skspritenode
face direction of cgpoint
. have managed so:
cgpoint direction = rwnormalize(offset); self.player.zrotation = atan2f(direction.y, direction.x);
how call skspritenode
animate rotation rather being instantaneous. possible keep same speed of rotation in animation no matter sprite should turn? in advance!
use skaction
:
cgpoint direction = rwnormalize(offset); float angle = atan2f(direction.y, direction.x); // speed of rotation (radians per second) float speed = 2.0; float duration = angle > m_pi_2 ? angle/speed : (angle + m_pi_2)/speed; [self.player runaction: [skaction rotatetoangle:angle duration:duration]];
Comments
Post a Comment