Game Development Reference
In-Depth Information
playerNode!.physicsBody!.dynamic = true
}
if impulseCount > 0 {
playerNode!.physicsBody!.applyImpulse(CGVectorMake(0.0,
40.0))
impulseCount--
}
}
This snippet is turning the player's dynamic volume back on, if it was off, so the player
will start reacting to gravity again. After that, it checks the impulseCount property. If
it is greater than 0, then it applies an impulse to the player and decrements the im-
pulseCount property by 1.
The purpose of this code is to put the game in an initial start state with the player station-
ary until you tap the screen to start. When the screen is tapped the first time, the game be-
gins.
The impulseCount property was added to introduce a new game element. The game is
going to use the impulseCount property to give the user a limited number of impulses
that can be used for thrusts. The impulseCount property will increment each time the
playerNode comes into contact with an orb and decrement every time the player taps
the screen. This means the user must be good at collecting orbs, or they will eventually
fall into oblivion and lose the game.
The next thing that needs to be changed is how the orb nodes are added to the scene. You
want to add many more. Before adding additional nodes, the code that currently adds the
nodes needs to be removed.
To remove this code, start by removing the orbNode property from the top of the
GameScene class. Find the following line in the declarations section of the GameScene
and remove it:
let orbNode : SKSpriteNode?
And then remove all of the following lines, which were used earlier to add the single
node:
orbNode = SKSpriteNode(imageNamed: "PowerUp")
orbNode!.position = CGPoint(x: 150.0, y: size.height - 25)
Search WWH ::




Custom Search