Using swift and spriteKit, how can I rotate SKSpriteNode around a point outside the node?

How can I rotate Node in SpriteKit around an arbitrary point?

I already have the answer β€œCreate a SKNode and set its position to the center of rotation. Add a Node that should rotate around this center as a child in the center of the node. Set the Node's child position (for example, radius, say x + 100). Change the property rotate the center of the Node so that the child node (s) rotates around the center point. The same thing works for cocos2d btw. "

But I really don’t understand how to write this in code :( I am starting very fast and it looks quite complicated. Can someone help me with the code?

+4
source share
1

.

    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)
+7

All Articles