Write Code to Interface with the Scene

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

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Chapter 8 Using the Scene Editor to Add Physics | TOC | Add Physics to the Player 👉

In Configure the View and Load the Scene, you learned how to load a scene file through code. If you recall, loading a scene file takes place in the viewDidLoad() method of the GameViewController.swift file and looks like this:

​ ​if​ ​let​ scene = ​GKScene​(fileNamed: ​"GameScene"​)

But loading the scene is only half of the story — you still need to write the code that interfaces with the objects within the scene, for example, the player node. In this section, you’ll concentrate on making that connection.

To begin, open the valsrevenge project in Xcode.

Using the Starter Project

You may continue using your project from the previous chapter, or you can use the starter project located in the projects/begin folder included with the code resources for this chapter. Either option is fine; the only benefit to using the starter project is that you won’t get stuck going forward if you missed an earlier step.

There’s also an ending project for this chapter that includes all of the code and resources you’ll be adding here. The end project is located in the projects/end folder included with the code resources for this chapter.

--

--

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.