So, I recently included the chipmunk in my iPhone/Android project for a mini-games which uses a little bit of physic.
The game is very simple, you grab objects and throw them so they fall into containers, with a couple of obstacles in the way
However, I’m having a problem where the callback for the collision isn’t called.
This is how I create my space and add my collision handler:
// CREATE SPACE
space = cpSpaceNew();
space->elasticIterations = 10;
cpSpaceAddCollisionHandler(space, 1, 1, &spriteCollision, NULL, NULL, NULL, this); // Listen for collisions
Here the declaration and definition of the spriteCollision function:
static int spriteCollision(cpArbiter *arb, cpSpace *space, void *data)
cocos2d::CCLog("#DBG sprite collision");
The initialisation occurs into the GameScene class, which is a subclass of CCScene, init function,
while the spriteCollision function is just a static function that doesn’t belong to the class but is declared at the top of the GameScene.cpp file.
I tried to make the spriteCollision function a static member of the class, pass it as “spriteCollision” instead of “&spriteCollision”, both made no difference.
Did anyone have the same problem ? Am I missing something?