Game Development Reference
In-Depth Information
Changing the Vertical Alignment of the Label Node
In the previous section, you saw how you can change the horizontal alignment of the
SKLabelNode using SKLabelNode 's horizontalAlignmentMode property. In
this section, you will see how you can change SKLabelNode 's vertical alignment.
Before getting started, go back to the GameScene.swift file and change it contents so
they match Listing 7-2 .
Listing 7-2 . The GameScene Class with the Simple Label at the Top of the Scene
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: frame.height
- simpleLabel.frame.height)
simpleLabel.horizontalAlignmentMode
= SKLabelHorizontalAlignmentMode.Center
addChild(simpleLabel)
}
}
As you look at this code, you will notice it looks like the code you used in the previous
section except that the SKLabelNode has been positioned at the top of the scene and
horizontalAlignmentMode has been explicitly set to the center. To see how this
looks, run the application again. It should now look like Figure 7-4 .
Search WWH ::




Custom Search