September 2018
Intermediate to advanced
434 pages
8h 47m
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 power-up 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:
crate.explode(gameScene: self)
} Read now
Unlock full access