Configure the View and Load the Scene

Apple Game Frameworks and Technologies — by Tammy Coron (79 / 193)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Add Nodes Using the Object Library | TOC | Next Steps 👉

In the Project Navigator, select the GameViewController.swift file to open it in the Source Editor. Locate and review the viewDidLoad() method. It looks like this:

​ ​override​ ​func​ ​viewDidLoad​() {
​ ​super​.​viewDidLoad​()

​ ​// Load 'GameScene.sks' as a GKScene. This provides gameplay-related content​
​ ​// including entities and graphs​
​ ​if​ ​let​ scene = ​GKScene​(fileNamed: ​"GameScene"​) {

​ ​// Get the SKScene from the loaded GKScene​
​ ​if​ ​let​ sceneNode = scene.rootNode ​as!​ ​GameScene​? {

​ ​// Copy gameplay-related content over to the scene​
​ sceneNode.entities = scene.entities
​ sceneNode.graphs = scene.graphs

​ ​// Set the scale mode to scale to fit the window​
​ sceneNode.scaleMode = .aspectFill

​ ​// Present the scene​
​ ​if​ ​let​ view = ​self​.view ​as!​ ​SKView​? {
​ view.​presentScene​(sceneNode)

​ view.ignoresSiblingOrder = ​true​

​ view.showsFPS = ​true​
​ view.showsNodeCount = ​true​
​ }
​ }
​ }
​ }

Some of this code in this method may look a little familiar, such as the line that reads view.ignoresSiblingOrder = true. This code is what dictates, in part, how the scene renders. Change that line to read:

​…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.