Adding a health crate
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 theCrate
class as a property of theGameScene
:let heartCrate = Crate()
At the bottom of the
GameScene
didMove
function, add theheartCrate
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 thestarRoll
conditional (new code in bold):// Each encounter has a 10% chance...