Game Development Reference
In-Depth Information
Adding
Some
Additional
Bling
to
the
GameScene
Now that you have all the orbs laid out nicely and the black holes are animating back and
forth across the game scene, it is time to add a little more bling to make the game scene
look just a little better. Specifically, I will show how to add some additional stars to the
scene, a planet surface, and finally I will show how to colorize the
playerNode
when it
comes into contact with a black hole.
Let's get started with adding some stars to the background. First, open the
Images.xcassets
folder in Xcode and select the image
Stars
. To add this image to
the scene, first add a declaration statement that will hold the reference to the
SKS-
priteNode
referencing the
Stars
image. This declaration should be added to the
GameScene
directly after the
backgroundNode
declaration.
let backgroundNode : SKSpriteNode?
let backgroundStarsNode : SKSpriteNode?
After adding the declaration, add the following lines to the
GameScene.init(size:
CGSize)
method immediately after the line that adds the
backgroundNode
to the
scene:
addChild(backgroundNode!)
backgroundStarsNode = SKSpriteNode(imageNamed: "Stars")
backgroundStarsNode!.anchorPoint = CGPoint(x: 0.5, y: 0.0)
backgroundStarsNode!.position = CGPoint(x: 160.0, y: 0.0)
addChild(backgroundStarsNode!)
There is one last thing you need to do before running the app and checking out the new
stars, and that is to move the stars in relation to the
playerNode
. Moving the stars in re-
lation to the player is pretty straightforward, but I do want to add a little coolness. I want
to do this by moving the stars at a slightly different rate than the background. I have modi-
fied the
update()
method to do just this. Take a look:
override func update(currentTime: NSTimeInterval) {
if playerNode!.position.y >= 180.0 {
backgroundNode!.position
= CGPointMake(backgroundNode!.position.x,