Reputation: 1579
I basically want to add a SKSpriteNode to the screen and I have no idea where the mistake it. So I include pictures of my three classes participating in this problem. I created a class for all the background stuff. There I use the function addChild()
to add my 56 Nodes to the View but they do not appear on the screen. Theoretically (for me) everything should work.
Hopefully you can help me adding the Nodes to the screen!
Edit: Updated the pictures.
Upvotes: 0
Views: 623
Reputation: 3405
When you call this:
GameScene().addChild(image)
you every time inside for
create the local GameScene
object, add image
to this object and when you move to the next iteration of the loop, this object is destroyed. In fact, after your loop thire is no one GameScene
object.
Second, you don't need to use var image = SKSpriteNode()
in your hintergrund
object. You every time set this reference to new object.
You have the cross references in code, try to make somthing like this:
class GameScene: SKScene {
...
override func didMoveToView(view: UIView) {
hintergrund.setBackgroundForScene(self, width: screenWidht)
}
}
class hintergrund {
...
class func setBackgroundForScene(gameScene: GameScene, width: CGFloat) {
...
for (...) {
...
gameScene.addChild(image)
}
}
}
Upvotes: 1