O'Reilly logo

Build iOS Games with Sprite Kit by Josh Smith, Jonathan Penn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required