Creating the health power-up 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:

  1. In GameScene.swift, instantiate a new instance of the Crate class as a property of GameScene:
            let heartCrate = Crate() 
  2. 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() 
  3. Locate the GameScene.didSimulatePhysics function. Find the code that spawns the power-up star. We can ...

Get Swift Game Development - Third Edition 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.