game_app
game_app

Reputation: 51

Cannot 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 the b2body in box2d?

but still i'm seeing the objects in stage.

Upvotes: 4

Views: 4667

Answers (2)

Slav
Slav

Reputation: 3

Box2D AS3 port has bugs, connected with DestroyBody function. Bug fix is here(in Russian).

Trouble is in contact pool. And you must remove bodies after your world's timestep has finished.

Upvotes: 0

iforce2d
iforce2d

Reputation: 8272

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.

Upvotes: 8

Related Questions