Game Development Reference
In-Depth Information
Chapter
7
Adding Points and Sound
In the previous chapter, I briefly introduced you to particle emitters, including a quick look
at some of Xcode's template emitters. After that, I showed you how to add a particle emit-
ter to the playerNode so that you could emulate engine exhaust whenever an impulse is
applied to the physicsBody .
In this chapter, I will talk about using SKLabelNode s to add labels to your Sprite Kit
games. Specifically, I will show you how to add a label that keeps up with the number of
impulses remaining for the SuperSpaceMan to use, and then I will show you how to add
scoring to the game to keep up with the number of orbs the SuperSpaceMan has collected.
At the end of the chapter, you will get a chance to revisit SKAction s when I show you
how to use them to play game sounds.
What Are SKLabelNodes?
As I mentioned earlier, Sprite Kit implements text labels using a class named SKLa-
belNode . The SKLabelNode class, just like all the nodes you have seen so far, is an ex-
tension of SKNode . It is a pretty simple class with only two init() methods and a hand-
ful of properties all focused on setting label fonts, colors, and layout.
The simplest way to use an SKLabelNode is shown in the following snippet:
let simpleLabel = SKLabelNode(fontNamed: "Copperplate")
simpleLabel.text = "Hello, Sprite Kit!";
simpleLabel.fontSize = 40;
simpleLabel.position = CGPoint(x: size.width / 2.0, y:
size.height / 2.0)
addChild(simpleLabel)
As you look at this code, you can see that it first creates the SKLabelNode class by
passing the init() method the name of the font you want to use. After that, you set the
Search WWH ::




Custom Search