Search code examples
swiftsprite-kit

Switch between parents - SpriteKit


In my game I have two SKNodes called "Center" rotating. I have several objects as the child of Center (the SKNode). I did this so I could let these objects orbit around Center. Although at certain points I want to switch to other SKNodes - "Center2". In this I have named one of the objects "Onject", which switched between parents I need to attach and detach at certain points in my game. I have tried, after doing self.addChild(Object) then doing Center.addChild(Object). My game crashed.

How do I switch between parents for objects?


Solution

  • there is a method called move(toParent:SKNode) to do exactly what you want, it will also fix the coordinates for you.