Collision Detection In Box2D – Using With Cocos2D

By | March 5, 2011

For an interactive game building using Box2D, collision detection of Box2D bodies is necessary. There is an easy way to implement collision detection in Box2D.

For checking whether two bodies have collided with each other in Box2D while using it with cocos2D, then use the following lines of code where ever you want to check collision.

if((contact.fixtureA == sourceFixture && contact.fixtureB == destinationFixture) ||
(contact.fixtureA == destinationFixture && contact.fixtureB == sourceFixture ))
{
//What you want to do after checking the collision?!!!
//That lines of code goes here!
//Simple and Pretty , isn't it?
}

Here you are cheking whether two box2D fixtures are in contact or not! And you can decide which fixtures you need to check for collision.

🙂

Leave a Reply

Your email address will not be published. Required fields are marked *