
Swift 3 Game Development
By :

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 GameScene
class to implement the SKPhysicsContactDelegate
protocol. SpriteKit can then inform the GameScene
class when contact events occur. Change the GameScene
class declaration line to look like this:
class GameScene: SKScene, SKPhysicsContactDelegate {
We will tell SpriteKit to inform GameScene
of contact events by setting the GameScene physicsWorld contactDelegate
property to the GameScene
instance. At the bottom of the GameScene didMove
function, add this line:
self.physicsWorld.contactDelegate = self
SKPhysicsContactDelegate
defines a didBegin
function that will fire when contact occurs. We can now implement this didBegin
function in the GameScene
class. Create a new function in the GameScene
class named didBegin
,...