Time for action – filtering collisions using a collision mask

In the previous section, we learned how to detect and ignore collisions. However, creating a special method for each collision pair and returning NO to ignore each collision is not the best way, especially if you want to completely ignore the collision between two object types.

Note

The approach shown previously works much better if you only need to filter some of the collisions. Then, you can have some kind of an if statement and return NO only for some object pairs.

So, let's see how we can filter collisions in a different way. We're going to set the collisionCategories property for the ground and the hunter and the collisionMask property for the stone physics bodies. Perform the following ...

Get Learning iPhone Game Development with Cocos2D 3.0 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.