I have a SKSpritenode
in the Level1.sks
called "ballNode".
This is loaded in the GameScene
via.
ballNode = childNode(withName: "ballNode") as? SKSpriteNode
ballNode?.physicsBody = SKPhysicsBody(circleOfRadius: (ballNode?.frame.size.width)! / 2)
ballNode?.physicsBody!.categoryBitMask = PhysicsCategory.ballCategory
ballNode?.physicsBody!.contactTestBitMask = PhysicsCategory.completeObjectNodeCategory
By default the ballNode
has a parent of the scene.
How can I add the ballNode
to a SKNode
called _gameNode
?
_gameNode = SKNode()
self.addChild(_gameNode)
When I try to add the ballNode
to the SKnode
via code. It throws a error.
_gameNode.addChild(ballNode!)
Thanks to KnightOfDragon. The solution is
ballNode?.move(toParent: _gameNode)