Preparing GameScene for contact events
Now that we have assigned the physics categories to our game objects, we can monitor for contact events in the GameScene class. Follow these steps to wire up the GameScene class:
First, we need to tell the
GameSceneclass to implement theSKPhysicsContactDelegateprotocol. SpriteKit can then inform theGameSceneclass when contact events occur. Change theGameSceneclass declaration line to look like this:class GameScene: SKScene, SKPhysicsContactDelegate {We will tell SpriteKit to inform
GameSceneof contact events by setting theGameScene physicsWorld contactDelegateproperty to theGameSceneinstance. At the bottom of theGameScene didMovefunction, add this line:self.physicsWorld.contactDelegate = self
SKPhysicsContactDelegatedefines adidBeginfunction that will fire when contact occurs. We can now implement thisdidBeginfunction in theGameSceneclass. Create a new function in theGameSceneclass nameddidBegin,...