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 collision groups


Sometimes, setting up collision categories and collision masks can be a little bit more than you need, especially when you only need to filter the collision between two object types; just like in our case!

Let's quickly review one more method to filter collisions using the collisionGroup property:

  1. First of all, we need to remove the code that sets collision categories and the collision mask. In the PhysicsHunter.m file, find the createPhysicsBody method and remove the following line:

    body.collisionCategories = @[@"hunters"];
  2. Then, open the PhysicsScene.m file and remove the following line from the addGround method:

    groundBody.collisionCategories = @[@"obstacles"];

    Also, remove the following line of code from the spawnStone method:

    stoneBody.collisionMask = @[@"hunters"];

    This will remove the collision filtering that we've added in the previous Time for action section.

  3. Now, it is time to implement collision filtering using the collision...