February 2017
Beginner to intermediate
258 pages
5h 31m
English
Now we can fire custom logic whenever the player runs into a crate. We will place our particle effect and award health or coins. Follow these steps to wire up the contact event:
GameScene.swift and locate the didBegin function, where we set our physics contact logic.explode function on our Crate class any time the player runs into a Crate. Add a new case for crate contact below the star powerup contact case, as shown here (new code in bold): case PhysicsCategory.powerup.rawValue:
player.starPower()
case PhysicsCategory.crate.rawValue: if let crate = otherBody.node as? Crate { // Call the explode function with a reference // to the GameScene: ...Read now
Unlock full access