How to remove sprite and shape with chipmunk?

How to remove sprite and shape with chipmunk?
0.0 0


I want to remove the physics sprite and the shape and the body when the physics sprite was collided.

The physics sprite was created with “createPhysicsSprite”,was able to be removed with “cc.Node.removeChild” .

But how to remove the body and the shape?

I tried to remove them with Space.removeShape and Space.removeBody ,got the following errors.

Uncaught Error: Assertion failed: This addition/removal cannot be done safely during a call to cpSpaceStep() or during a query.
Put these calls into a post-step callback.


you cant delete something INSIDE physics step

eg: you want to remove the bullet when a bullet hits a wall, you add collision callback between bullet and wall. in this callback, you tried to delete bullet.

this won’t work, as callback is still inside the physics step.

what you can do is:
label the bullet as “to delete” in collision callback, then when the physics step is finished, during your normal game loop, you can then delete all objects that has marked as “to delete”


how can I know that step is finished?

Will this work?

function update() {


Reviving this thread.

How do I get the associated PhysicsSprites from the collisionBegin, collisionPreSolve, collisionPostSolve, collisionSeparated callbacks?

I can get the bodies and shapes from the arbiter parameter, but can not get the sprites.

collisionBegin: function(arbiter, space)
    var arrayShapes = arbiter.getShapes();
    var bodyAsteroid = arrayShapes[1].body;



I think you can try set the sprite to the body/shape user data.