Wiring up crate contact events
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:
- In Xcode, open
GameScene.swiftand locate thedidBeginfunction, where we set our physics contact logic. - We need to call the
explodefunction on ourCrateclass any time the player runs into aCrate. Add a new case for crate contact below the starpowerupcontact 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:    ...