Game Development Reference
In-Depth Information
Docs/#cpShape .
The next four parameters are pointers to C callback methods for the four collision
stages: begin , pre-solve , post-solve , and separation (the same as the EndContact
event in Box2D). These serve the same purpose as the corresponding callbacks in
Box2D. Most of the time you'll be interested only in the begin and separation
I pass NULL for pre-solve and post-solve, because I'm not interested in handling these.
You can use these methods to influence the collision or to retrieve the collision force in
the post-solve step. The final parameter is an arbitrary data pointer you can pass on to
the callback methods if you need it. I don't, so I set it to NULL as well.
With that, you have a working collision callback mechanism.
Joints for Chipmunks
The Chipmunk example project also needs its own implementation of ad-
dSomeJointedBodies . The setup is more verbose than for Box2D, as shown in
Listing 12-13 . You'll recognize most of the code as setting up static and dynamic bod-
ies—if you find that code familiar, feel free to skip to the end where the joints are cre-
Listing 12-13. Creating Three Bodies Connected with Joints
-(void) addSomeJointedBodies:(CGPoint)pos
float mass = 1.0f;
float moment = cpMomentForBox(mass, TILESIZE, TILESIZE);
float halfTileSize = TILESIZE * 0.5f;
int numVertices = 4;
CGPoint vertices[] =
ccp(−halfTileSize, -halfTileSize),
ccp(−halfTileSize, halfTileSize),
Search Nedrilad ::

Custom Search