I am using Chipmunk in a Cocos2D iOS app.
All is running very well, great stuff.
I have, however, just started to try and use the physics system to do some of my initial level set-up.
I am defining 2D trigger volumes in my editor.
I would like these trigger volumes to collect all the items that may be activated within their volume on an initial physics step.
I would then like to remove this callback, and add a callback for the main-character striking the trigger volume.
When the trigger volume is stuck, all the items it touches will be activated.
My code is below:
Code: Select all
// Set up the physics callbacks - the level set-up
cpSpaceAddCollisionHandler( physicsSpace, CT_ACTIVATOR, CT_DYNAMIC, collectActivees, NULL, NULL, NULL, NULL );
cpSpaceAddCollisionHandler( physicsSpace, CT_ACTIVATOR, CT_DYNAMIC_DAMAGE, collectActivees, NULL, NULL, NULL, NULL );
// Run an initial physics step and then remove the set-up callbacks, add the ones that count
[self physicsStep:LEVEL_FRAME_UPDATE];
cpSpaceRemoveCollisionHandler( physicsSpace, CT_ACTIVATOR, CT_DYNAMIC );
cpSpaceRemoveCollisionHandler( physicsSpace, CT_ACTIVATOR, CT_DYNAMIC_DAMAGE );
cpSpaceAddCollisionHandler( physicsSpace, CT_PROTAGONIST, CT_ACTIVATOR, activateActivees, NULL, NULL, deactivateActivees, NULL );
When I leave the cpSpaceRemoveCollisionHandler calls in I either get mixed up callback function pointers or crashes in the next physics step.
Am I doing something wrong?
Is there a safe point to remove collision handlers?
I am using Chipmunk v5.3.4 (Debug Enabled).
Thank you for your help.