Detecting Collisions Between Bodies
Up to this point, the physics engine has been handling collisions and contact between the bodies for us on its own. We haven’t needed to intervene in any way. But now we have to. We want to be notified when the ball hits a target so we can increase the score. We also want to know when the ball hits either a target or a bumper so we can display some special effects and play sounds.
That’s where the category bitmasks and the contact delegate comes in. By the end of this section, you’ll know how to tell Sprite Kit which collisions you care about.
First, let’s register our scene object as the contact delegate to get told when physics bodies collide with each other. In the RCWMyScene.m file, change the class ...
Get Build iOS Games with Sprite Kit 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.