Load the First Game Scene

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

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Present the Title Scene | TOC | Present the Game Over Scene 👉

As you learned earlier, the loadSceneForLevel(_:) method in the SKScene+SceneManager.swift file is responsible for loading the correct game scene depending on the level the player is about to begin. It does so using the following code:

​ ​GKScene​(fileNamed: ​"GameScene_​​\(​level​)​​"​)

The value stored in the level argument determines which game scene file to load; for example, the GameScene_1.sks file represents Level 1, the GameScene_2.sks file represents Level 2, and so on. Of course, none of these files exist right now, so you’ll need to make at least one — and the easiest way to do so is to rename what you already have.

In the Project Navigator, select the GameScene.sks file and rename it GameScene_1.sks. (Note: Do not rename the GameScene.swift file; leave that as it is.)

Build and run the project and you’ll see the new title scene, as shown. After a moment or two, tap the Start New Game button to start a new game, which then loads the first scene.

images/AddingMoreScenesAndSavingTheGame/build-title.png

With the title scene working, you’re ready to work on the code necessary to present the game over scene.

--

--

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.