Game Development Reference
In-Depth Information
Method
Purpose
The
addChild(_:)
method adds a node to the end of the receiver's collec-
tion of child nodes.
(1) addChild()
The
insertChild(_:atIndex:)
method inserts a child node at a specific
position in the receiver's collection of child nodes.
(2) inser-
tChild(_:atIndex:)
(3) removeFromPar-
ent()
removeFromParent()
removes the receiving node from its parent.
These are the three methods you will use to build the scene's node tree. The easiest way to
see how these methods work is through a simple example. Take a look at the following se-
quence:
var gameScene = SKScene(size: CGSizeMake(320.0, 568.0))
var node1 = SKSpriteNode()
var node2 = SKSpriteNode()
var node3 = SKSpriteNode()
gameScene.addChild(node1)
gameScene.addChild(node2)
gameScene.addChild(node3)
Here you are creating an
SKScene
named
gameScene
. You then create three nodes and
Figure 2-2
.
The gameScene's children property after adding three nodes