How to rotate a sprite node in sprite kit?

Vince picture Vince · Oct 15, 2013 · Viewed 38.3k times · Source

I am making a game and I'm having troubles with rotating a sprite node, This is the code I have; What do I have to add to turn it, let's say 45 degrees?.

SKSpriteNode *platform = [SKSpriteNode spriteNodeWithImageNamed:@"YellowPlatform.png"];
platform.position = CGPointMake(CGRectGetMidX(self.frame), -200+CGRectGetMidY(self.frame));
platform.size = CGSizeMake(180, 10);
platform.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:platform.size];
platform.physicsBody.dynamic = NO;
[self addChild:platform];

Answer

quaertym picture quaertym · Dec 30, 2013

Just do this without using actions:

sprite.zRotation = M_PI / 4.0f;

And in Swift 4:

sprite.zRotation = .pi / 4