Why world.DestroyBody(body) it´s not working?

Discuss issues specific to the Flash/AS3 port of Box2D
torpedete
Posts: 33
Joined: Wed Jul 15, 2009 7:27 am

Why world.DestroyBody(body) it´s not working?

Postby torpedete » Tue Dec 11, 2012 8:41 am

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.

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.

torpedete
Posts: 33
Joined: Wed Jul 15, 2009 7:27 am

Re: Why world.DestroyBody(body) it´s not working?

Postby torpedete » Wed Dec 12, 2012 3:35 am

Hi again,

I added all the bodies to destroy to an array, and then I´m trying to do it this way but it doesn´t work... I´m totally stuck here :(

Code: Select all

//inside of the loop function
if (destroyBodies) {
     for (var i:int = 0; i < arrayBodies.length; i++) {
          world.DestroyBody(arrayBodies[i]);
     }
     destroyBodies= false;
}
world.Step(1 / 30, 10, 10);
//rest of the code...


Return to “Flash”



Who is online

Users browsing this forum: No registered users and 2 guests