Game Development Reference
In-Depth Information
Add this line directly after the definition of the
scoreTextNode
constant. The next
thing you need to do is modify the properties of the
impulseTextNode
. The code to
do this is in the following snippet:
impulseTextNode.text = "IMPULSES : \(impulseCount)"
impulseTextNode.fontSize = 20
impulseTextNode.fontColor = SKColor.whiteColor()
impulseTextNode.position = CGPointMake(10.0, size.height
- 20)
impulseTextNode.horizontalAlignmentMode
= SKLabelHorizontalAlignmentMode.Left
addChild(impulseTextNode)
As you examine this snippet, you will notice that you have seen all of this before. This
code sets the text of the node to “IMPULSES :” plus the value currently stored in the in-
stance variable
impulseCount
. It then sets the font size to 20 and the color to white.
After that, it sets the position of the label node to 10 points from the left side of the scene
and 20 points from the top of the scene. The final property change sets
horizontalA-
lignementMode
to
SKLabelHorizontalAlignmentMode.Left
so that the left
side of the text is anchored to the node's origin. After that, the
impulseTextNode
is
added to the scene. Add this snippet to bottom of the
GameScene
's
init(size:
CGSize)
method and save your work.
There are two more changes you need to make to update the displayed impulse count. The
first is to modify the text in the
impulseTextNode
to reflect each time the player col-
lects an orb, and the second is to modify the
impulseTextNode
each time the player
uses an impulse.
Starting with incrementing the impulse count, you need to modify the
didBe-
ginContact()
method again. Specifically, you need to modify the
if
statement that
handles contact with orb nodes. Take a look at the following snippet:
if nodeB.name == "POWER_UP_ORB" {
impulseCount++
impulseTextNode.text = "IMPULSES : \(impulseCount)"
score++
scoreTextNode.text = "SCORE : \(score)"
nodeB.removeFromParent()
}