Smashing Physics

Your game has come a long way! Preview the app, and you should see barriers whizzing toward the player. The hero can jump in different ways to avoid collisions, and the ground moves faster as time progresses. The last order of business is to detect collisions between the player and the barriers. SpriteKit can handle much of the collision detection for us. You just have to tell it which objects should collide and when a collision should occur.

You need to create an enum for PlayScene, just above the didMoveToView method. You’ll use this identify the hero and barrier objects for the purposes of collision detection:

enum ColliderType:UInt32 {    case Hero = 1    case Block = 2}

Get Learning Swift™ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.