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];
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 instantly SKAction *rotation = [SKAction rotateByAngle: M_PI/4.0 duration:0]; //and just run the action [yourNode runAction: rotation];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With