Game Development Reference
In-Depth Information
The final line in the snippet adds the backgroundNode to your scene. To see what you
have just accomplished, save your work and run the application again. You should now
see your background displayed, as shown in Figure 1-10 .
Figure 1-10 . The backgroundNode added to the GameScene
That was easy enough. Now, let's add your player to your scene. Adding the player node
is just as easy as adding the background. Take a look at the following snippet:
// add the player
playerNode = SKSpriteNode(imageNamed: "Player")
playerNode!.position = CGPoint(x: size.width / 2.0, y: 80.0)
addChild(playerNode!)
As you can see, you are creating a new SKSpriteNode using the image named Play-
er . You then set the position of the playerNode and add it to the scene. Notice one dif-
ference here. You did not set the anchor point of the playerNode . This is because the
default anchor point of all SKNode s is (0.5, 0.5), which is the center of the node. Again,
don't worry about the positions or anchorPoint s for now. I will be discussing them in
the next chapter.
Search WWH ::




Custom Search