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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.