Game Development Reference
In-Depth Information
Everything is the same from the previous section except the line following the increment
of the impulse count. This line sets the text of the impulseTextNode to “IMPULSES
:” plus the value of the impulseCount variable that was just incremented on the line
before. Make these changes to the if statement and save your changes.
The last change you need to make to display the current impulse count is to modify the
impulseTextNode each time an impulse is used by the player. To do this, you need to
go back the GameScene 's touchesBegan() method and modify the if statement
that applies the impulse to the playerNode to look like the following snippet:
if impulseCount > 0 {
playerNode!.physicsBody!.applyImpulse(CGVectorMake(0.0,
40.0))
impulseCount--
impulseTextNode.text = "IMPULSES : \(impulseCount)"
engineExhaust!.hidden = false
NSTimer.scheduledTimerWithTimeInterval(0.5, target:
self,
selector: "hideEngineExaust:", userInfo:
nil, repeats: false)
}
There is only one change to the body of this if statement, and that is the line following
the decrement of the impulseCount instance variable. On this line, the im-
pulseTextNode 's text property is being modified just like you did before, except this
time the text node will be set to “IMPULSES :” plus the recently decremented im-
pulseCount . When you are finished looking at this snippet, save your changes and run
the game again. You will now see the addition of the impulse count label in the top-left
corner, as shown in Figure 7-9 .
Search WWH ::




Custom Search