- 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 the b2body in box2d?
but still i'm seeing the objects in stage.
If you are trying to do this inside the world's Step() function (eg in a contact listener), it will not work because the world is still processing the bodies. You will need to make a note of which bodies you want to destroy, and then destroy them after the world's time step has finished.
Also, I'm not sure what language you are using but it seems a little strange that this loop will destroy a body and then call GetNext() on the thing you just destroyed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With