I am making a game with Swift 3 and SpriteKit, and I am trying to declare a global variable to work with it in the rest of the GameScene class, but I cannot. What I've done:
class GameScene: SKScene { ... let personaje = SKSpriteNode(imageNamed: "Ball2.png") ...
After a global declaration, I tried to use it in sceneDidLoad just like this:
... personaje.position = CGPoint.zero addChild(personaje) ...
I don't know why, but Xcode returns this error:
*** Application termination due to the uncaught exception "NSInvalidArgumentException", reason: "Accepted to add an SKNode that already has a parent: name: '(null)' texture: ['Ball2.png' (150 x 146)] position : {0, 0} scale: {1.00, 1.00} size: {150, 146} anchor: {0.5, 0.5} rotation: 0.00 '
Thanks in advance for your ideas and solutions!
source share