O'Reilly logo

Game Development with Swift by Stephen Haney

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Integrating scenes into the game

Next, we will create a new class to manage the encounters in our game. Add a new Swift file to your project and name it EncounterManager.swift. The EncounterManager class will loop through our encounter scenes and use the positional data to create the appropriate game object classes in the game world. Add the following code inside the new file:

import SpriteKit class EncounterManager { // Store your encounter file names: let encounterNames:[String] = [ "EncounterBats" ] // Each encounter is an SKNode, store an array: var encounters:[SKNode] = [] init() { // Loop through each encounter scene: for encounterFileName in encounterNames { // Create a new node for the encounter: let encounter = SKNode() // Load this scene ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required