April 2021
Beginner to intermediate
506 pages
11h 57m
English
Attributed strings in SpriteKit work very much the same as they do in UIKit. With attributed strings, you can add additional attributes such as font styles and kerning. In this case, you’re using an attributed string to provide a line break in a multiline label while also keeping the text centered—something the SKLabelNode class can’t seem to do natively.
In the GameScene.swift file, add the following method below the setupLabels() method; you’ll use this method to display a message in the middle of the screen:
| | func showMessage(_ message: String) { |
| | // Set up message label |
| | let messageLabel = SKLabelNode() |
| | messageLabel.name = "message" |
| | messageLabel.position = CGPoint(x: frame.midX, y: ... |
Read now
Unlock full access