How can I rotate a Node in SpriteKit around an arbitrary point?
I have already googled a answer "Create an SKNode and set its position to the center of rotation. Add the node that should rotate around that center as child to the center node. Set the child node's position to the desired offset (ie radius, say x + 100). Change the rotation property of the center node to make the child node(s) rotate around the center point. The same works for cocos2d btw."
But I really dont understand how to write this in code :(. Im very beginner in swift and this looks quite difficult. Can anyone give me a help with code?
I did it this way after a few hours of experimenting.
var fish: SKSpriteNode = SKSpriteNode(imageNamed: "fish")
fish.anchorPoint = CGPoint(x:CGFloat(-0.5),y:CGFloat(-0.2))
fish.zPosition = CGFloat(y+0.5)
fish.position = CGPoint(x:CGFloat(x),y:CGFloat(-60-96*(y-3)))
var jump = SKAction.rotateToAngle(CGFloat(3.14), duration: NSTimeInterval(1))
fish.runAction(jump)
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