Game Development Reference
In-Depth Information
the player to it. First, add the following declaration of the
foregroundNode
immedi-
ately after the declaration of the
backgroundNode
:
let foregroundNode : SKSpriteNode?
Next, create and add the following
foregroundNode
instance directly after where you
added the
backgroundNode
to the scene:
foregroundNode = SKSpriteNode()
addChild(foregroundNode!)
Now find the location in the
init()
method where you added the
playerNode
and
orbNode
to the scene and change the
addChild()
invocations to the following:
foregroundNode!.addChild(playerNode!)
foregroundNode!.addChild(orbNode!)
Once you have the
playerNode
and
orbNode
added to the new
foregroundNode
,
find where you are setting the position of the
playerNode
and change its
position
property using the following
CGPoint
:
playerNode!.position = CGPoint(x: self.size.width / 2.0, y:
180.0)
Now find where you are setting the
playerNode.physicsBody.dynamic
property
and turn off the player's dynamic volume.
playerNode!.physicsBody!.dynamic = false
You are doing this so the player does not fall off the screen if you don't tap the screen in
time. Next, add the following new property to the
GameScene
immediately after the
definition of the
orbNode
:
var impulseCount = 4
Now change the
touchesBegan()
method to match the following:
override func touchesBegan(touches: NSSet, withEvent event:
UIEvent) {
if !playerNode!.physicsBody!.dynamic {