Game Development Reference
In-Depth Information
At this point, the node tree contains three nodes—
node1
,
node2
, and
node3
(in that
order). Now, if you executed the following snippet, you would have a node tree that
looked like
Figure 2-3
:
var node4 = SKSpriteNode()
gameScene.insertChild(node4, atIndex: 2)
Figure 2-3
.
The gameScene's node tree after inserting a fourth node
The children property now contains four nodes, with
node4
being inserted between
node2
and
node3
. Let's do one last thing and remove a node.
node2.removeFromParent()
By invoking
node2
's
removeFromParent
method, you have removed
node2
from
Figure 2-4
.
The gameScene's node tree after removing node4
There is one last thing you need to look at, and that is nested nodes. Because the node tree
is part of
SKNode
and because
SKSpriteNode
is extended from
SKNode
, it can have