Hi there,
at first, I should say that I´m a total newbie, so maybe I can say some "stupid" things, but well, I´m gonna try to explain you my problem...
I´m making one game and when I finnish one level, I want to remove all the bodies of the world (except the 4 walls arround the screen) but this is not working for me... I´m pasting the code of the function that should do that.
The part removing the graphics of the body it´s working properly, everything is fine.
The trace(b) gives me the result, all the bodies I want to delete, but the next line, with the world.DestroyBody() is not working. Can anyone tell me why? I suposse it´s something basic, but I don´t get it...
Thanks.
at first, I should say that I´m a total newbie, so maybe I can say some "stupid" things, but well, I´m gonna try to explain you my problem...
I´m making one game and when I finnish one level, I want to remove all the bodies of the world (except the 4 walls arround the screen) but this is not working for me... I´m pasting the code of the function that should do that.
Code: Select all
private function deleteBodiesFromLevel():void
{
for (var b:b2Body = world.GetBodyList(); b; b = b.GetNext()) {
if (b.GetUserData() && b.GetUserData().category!= "wall") {
removeChild(b.GetUserData().graphic);
b.GetUserData().graphic= null;
trace(b);
world.DestroyBody(b);
}
}
}The part removing the graphics of the body it´s working properly, everything is fine.
The trace(b) gives me the result, all the bodies I want to delete, but the next line, with the world.DestroyBody() is not working. Can anyone tell me why? I suposse it´s something basic, but I don´t get it...
Thanks.