Book Image

Cocos2d Game Development Blueprints

By : Jorge Jordán
Book Image

Cocos2d Game Development Blueprints

By: Jorge Jordán

Overview of this book

Table of Contents (15 chapters)
Cocos2d Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Advanced collision detection with Chipmunk


Chipmunk provides powerful tools to detect and manage collisions between physics bodies, taking advantage of CCPhysicsBody and CCPhysicsShape properties and implementing the CCPhysicsCollisionDelegate protocol.

CCPhysicsBody and CCPhysicsShape properties

Chipmunk's bodies and shapes have three properties we can take advantage of to define the collision relationship between them:

  • collisionCategory: This is the collision category that defines an object.

  • collisionMask: This is the property that defines the objects that can collide with it. This property is an array that contains the collision categories that will collide with the object.

  • collisionGroup: Thanks to this property, we can define a group of objects that won't collide with each other.

These properties allow us to define the collision relationships to achieve the effect desired. For example, let's make the star collide with all the bodies and vice versa.

In GameScene.m, add the following lines...