I was wondering how to make a Sprite do an orbit on a determinated point in SpriteKit. I tried to set the anchorPoint of the Sprite orbiting with the center point but it doesn't work. Please can someone help me?

  • \$\begingroup\$ When you say "orbit" do you mean travel a circular path around the centre point or do you mean follow a path around a centre point that is more controlled by things like gravity, mass, velocity etc. i.e. using celestial mechanics… \$\endgroup\$ – Craig Feb 14 '16 at 1:44

Use the parenting to your advantage. From the SKNode Class Reference:

When a node’s coordinate system is scaled or rotated, this transformation is applied both to the node’s own content and to that of its descendants.

First, create an SKNode (your center node) and set its position to the center of the orbit. Next, add the SKSpriteNode that should be orbiting as child to the center node. Set the child node's position to the radius of the orbit ((0, 50) for a radius of 50).

When you rotate the center node, the child will "orbit" around it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.