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 ...

Get Game Development with Swift now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.