Game Development Reference
In-Depth Information
text property of the label. You then set the fontSize and position properties. Fin-
ally, you add the label node to the scene.
Let's give this a try in a sample application. Go back to Xcode and create a new Game
project using Swift as the language. When you have your new project created, go to the
GameScene.swift file and change its body to match Listing 7-1 .
Listing 7-1 . The New GameScene Class
import SpriteKit
class GameScene: SKScene {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
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)
}
}
When you take a look at this listing, you will see it contains a simple init() method
that takes an NSCoder . Inside the init() method this super.init() method is
called, and then you see the SKLabel -related code.
This code looks exactly like the earlier snippet that added an SKLabelNode . Run the
app and take a look at the results. The new app should look like Figure 7-1 .
Search WWH ::




Custom Search