April 2021
Beginner to intermediate
506 pages
11h 57m
English
Inside the Extensions group, create a new file (⌘N) using the iOS Swift File template. Name the new file GameScene+PhysicsContact.swift and replace its contents with the following:
| | import SpriteKit |
| | |
| | extension GameScene: SKPhysicsContactDelegate { |
| | func didBegin(_ contact: SKPhysicsContact) { |
| | let collision = contact.bodyA.categoryBitMask |
| | | contact.bodyB.categoryBitMask |
| | |
| | switch collision { |
| | default: |
| | break |
| | } |
| | } |
| | } |
This code is the start of your physics contact manager.
To keep the code organized and make it easier to see what contacts are taking place, you’ll use code comments. Add the following code just above the line that reads default::
| | // MARK: - Player | Collectible ... |
Read now
Unlock full access