Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 steps:

  1. Open the PhysicsScene.m file and remove the following ccPhysicsCollisionBegin: method for the stone and the ground pair, the one where we return NO:

    -(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair
                             stone...