Game Development Reference
In-Depth Information
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
You now have an action that will play the orb_pop.wav file. It's now time to add the
code to play the sounds. To do this, you need to make one more modification to the
didBeginContact() method to add the code to run your new action. Take a look at
the modified if statement that handles orb contact, shown here:
if nodeB.name == "POWER_UP_ORB" {
self.runAction(orbPopAction)
self.impulseCount++
self.impulseTextNode.text = "IMPULSES
: \(self.impulseCount)"
self.score++
self.scoreTextNode.text = "SCORE : \(self.score)"
nodeB.removeFromParent()
}
Here you can see a new line, at the beginning of the if statement, that runs the or-
bPopAction whenever the contacted node's name is POWER_UP_ORB . Make this
change to the if statement and run the game again. Now every time the playerNode
comes into contact with an orb node, the orb_pop.wav sound is played.
Summary
In this chapter, you saw how you can use SKLabelNode s to add labels to your Sprite Kit
games. Specifically, you saw how you can display the remaining number of impulses and
how to add scoring to the game to keep up with the number of orbs the spaceman has col-
lected. At the end of the chapter, you got a chance to revisit SKAction s when you added
sound to the game.
In the next chapter, you will get a chance to add new scenes to the game and do some
scene transitions when you add menuing and the ability to start a new game.
Search WWH ::




Custom Search