Game Development Reference
In-Depth Information
at the same rate as the background node. This will make the planet's surface fall away as
the player gets higher and higher in the scene.
Let's go ahead and do this. First, add a new SKSpriteNode declaration directly follow-
ing the declaration of the backgroundStarsNode .
let backgroundStarsNode : SKSpriteNode?
let backgroundPlanetNode : SKSpriteNode?
Next, insert the code to add the backgroundPlanetNode to the scene. This code
should immediately follow the addition of the backgroundStarsNode , as shown
here:
addChild(backgroundStarsNode!)
backgroundPlanetNode = SKSpriteNode(imageNamed:
"PlanetStart")
backgroundPlanetNode!.anchorPoint = CGPoint(x: 0.5, y: 0.0)
backgroundPlanetNode!.position = CGPoint(x: 160.0, y: 0.0)
addChild(backgroundPlanetNode!)
Now, find the line of code that sets the position of the playerNode (in the
init(size: CGSize) method) and change the position to match the following:
playerNode!.position = CGPoint(x: size.width / 2.0, y:
220.0)
Finally, modify the update method to move the backgroundPlanetNode at the same
rate as the backgroundNode .
override func update(currentTime: NSTimeInterval) {
if playerNode!.position.y >= 180.0 {
backgroundNode!.position =
CGPointMake(backgroundNode!.position.x,
-((playerNode!.position.y - 180.0)/8));
backgroundStarsNode!.position =
CGPointMake(backgroundStarsNode!.position.x,
-((playerNode!.position.y - 180.0)/6));
backgroundPlanetNode!.position =
CGPointMake(backgroundPlanetNode!.position.x,
-((playerNode!.position.y - 180.0)/8));
Search WWH ::




Custom Search