
Swift 3 Game Development
By :

We have taken many steps to create our crate system. Now we can add our first crate: a crate in the GameScene
class that will award health points to the player. Follow these steps to wire up the heart crate:
In GameScene.swift
, instantiate a new instance of the Crate
class as a property of the GameScene
:
let heartCrate = Crate()
At the bottom of the GameScene
didMove
function, add the heartCrate
to the node tree and call the function that makes it award a heart:
// Spawn the heart crate, out of the way for now self.addChild(heartCrate) heartCrate.position = CGPoint(x: -2100, y: -2100) heartCrate.turnToHeartCrate()
Locate the GameScene.didSimulatePhysics
function. Find the code that spawns the power-up star. We can add on to this code to spawn our heart crate randomly after some encounters. Add the following code below the starRoll
conditional (new code in bold):
// Each encounter has a 10% chance...