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:
Open the
PhysicsScene.m
file and remove the followingccPhysicsCollisionBegin:
method for the stone and the ground pair, the one where we returnNO
:-(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair stone...