Game Development Reference
In-Depth Information
doesn't fluctuate heavily (it really shouldn't anyway), using a fixed-time-step approach
works very well.
The PhysicsSprite class does all the position and rotation updates for you.
A Chipmunk Collision Course
C callback methods handle collisions in Chipmunk. In the PhysicsChipmunk01 project,
I've added the contactBegin and contactEnd static methods (in Listing 12-12 ),
which do exactly the same as their Box2D counterparts—change the color of boxes
that are in contact to magenta.
Listing 12-12. Collision Callbacks a la Chipmunk
static int contactBegin(cpArbiter* arbiter, struct cpSpace* space, void* data)
BOOL processCollision = YES;
cpBody* bodyA;
cpBody* bodyB;
cpArbiterGetBodies(arbiter, &bodyA, &bodyB);
PhysicsSprite* spriteA = (__bridge PhysicsSprite*)bodyA-> data;
PhysicsSprite* spriteB = (__bridge PhysicsSprite*)bodyB-> data;
if (spriteA ! = nil && spriteB ! = nil)
spriteA.color = ccMAGENTA;
spriteB.color = ccMAGENTA;
return processCollision;
static void contactEnd(cpArbiter* arbiter, cpSpace* space, void* data)
cpBody* bodyA;
cpBody* bodyB;
Search Nedrilad ::

Custom Search