How to rotate a sprite node in sprite kit?
Just do this without using actions:
sprite.zRotation = M_PI / 4.0f;
And in Swift 4:
sprite.zRotation = .pi / 4
You make SKAction for the rotation and run that action on the node.for example:
//M_PI/4.0 is 45 degrees, you can make duration different from 0 if you want to show the rotation, if it is 0 it will rotate instantlySKAction *rotation = [SKAction rotateByAngle: M_PI/4.0 duration:0]; //and just run the action[yourNode runAction: rotation];
sprite.zRotation = M_PI_4;
[sprite runAction:[SKAction rotateByAngle:M_PI_4 duration:0]];
are not the same.
running the SKAction will animate the change even if the duration is 0 it will do it over very short time. changing the zRotation will show it in the new rotation.
why this is important: if you add new sprite doing on it [SKAction rotateByAngle:] will create flickering/ugliness in the sprite as it comes on the view.
if the sprite is on the screen and you want to rotate it changing the zRotation will not be as nice as rotatebyAngle: even with 0 duration.