Unable to destroy the body (Box2d)

- for (var bb1:b2Body= world.GetBodyList(); bb1; bb1 = bb1.GetNext()) { if (bb1.GetUserData() is Sprite) { world.DestroyBody(bb1); } } world=null; 

Is it correct to remove b2body in box2d?

but still i see the objects in the stage.

+4
source share
2 answers

If you try to do this inside the world function Step () (for example, in the contact listener), this will not work, because the world still processes bodies. You will need to indicate which bodies you want to destroy, and then destroy them after completing the world step.

Also, I'm not sure which language you are using, but it seems strange that this loop will destroy the body and then call GetNext () on the item you just destroyed.

+8
source

The Box2D AS3 port has errors related to the DestroyBody function. Bug fix here (in Russian).

The problem is in the contact pool. And you must remove the body after your timestep world is finished.

0
source

Source: https://habr.com/ru/post/1388707/


All Articles