In the Note:
Besides the FPS, SpriteKit also displays the count of nodes that it rendered in the last pass.
I found that the node count showed +1 more than the SKSpriteNode children I added:
let background = SKSpriteNode(imageNamed: "background1")
let zombie = SKSpriteNode(imageNamed: "zombie1")
addChild(background) // node 1
addChild(zombie) // node 2
I reread Chapter 1: Sprites :: Page 54 Nodes and z-position and found this fun fact.
Every node has a property you can set named zPosition, which defaults to 0.
I implemented a free function outside of GameScene to test the SKScene type.
func isNode(test gameScene: SKScene) {
print(#function + " zPosition: \(gameScene.zPosition)")
gameScene.zPosition = -2 // try to set before background
print(#function + " zPosition -2: \(gameScene.zPosition)")
}
// And called it within didMove(to:)
isNode(test: self)
GameScene’s zPosition was 0.0 so it must be the +1 node.
…But I when I tried to modify that value I got this in the debugger:
SKScene: Setting the zPosition of a SKScene has no effect.
This got me thinking:
I’m assuming more than one SKScene node may exist per app.
If the background zPosition is -1, and the GameScene (it’s parent) is always 0.0…
Question 1: Is GameScene’s zPosition 0.0 only compared to other SKScenes (parent nodes)?
Question 2: Or is GameScene only given a zPosition property because it is a node?
Cheers!
Rebecca