Add New Scenes

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

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Chapter 15 Adding More Scenes and Saving the Game | TOC | Present the Title Scene 👉

At the moment, Val’s Revenge uses a single game scene. Although it’s entirely possible to stuff more content and logic into this game scene, you’ll take a different approach by creating two separate classes — TitleScene and GameOverScene — each using their own scene file. The benefit of multiple scenes and classes is that your game-related logic is kept separate from the other logic. Why is this important?

Suppose you had a menu scene or a settings scene where players were able to make certain selections or change options, like the game’s sound settings or whether or not the player prefers left-sided or right-sided controls. Now imagine if you stuffed the code necessary to support these two scenes inside of the GameScene class. Before you know it, you’d have a massive class that does way too much and will, no doubt, be difficult to maintain.

To avoid these massive, over-bloated classes, you’re betting off creating multiple classes and scenes, which is what you will do here. To help speed up this process, some of the work has already been done for you; you just need to add the resources to your project and make a few changes to the existing code.

Adding the Resources

To begin, open the valsrevenge project in Xcode.

--

--

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.