Destroy after collision

Topics: User Forum
May 7, 2011 at 5:30 PM

Hi all,

 

In my game I am creating body's (body_1 and body_2)) every X seconds to check the result of that collision. Body_1 is disposed in OnSeparation lik this:

  private void TestOnSeparation(Fixture fixtureA, Fixture fixtureB)
        {
            string a = fixtureB.Body.UserData as string;
            if (a == "destroy") fixtureB.Dispose();
           
        }
I want to destroy body_2 some time after the collision or if body_2 is sleeping, but new bodys are created before the collision.

Bodys are created like this:

         body_1:   testcue = BodyFactory.CreateCircle(world, 20f / (2f * MeterInPixels), 1f, cueBallBody.Position);
         body_2:   testredBody = BodyFactory.CreateCircle(world, 20f / (2f * MeterInPixels), 1f, redBody[ident].Position);

how to dispose Body_2 ?

Thanks in advance,

GROOVER


May 17, 2011 at 1:04 PM
groover wrote:

Body_1 is disposed in OnSeparation lik this:

            if (a == "destroy") fixtureB.Dispose();
I want to destroy body_2 some time after the collision

Note that first line of code you have above won't destroy your Body_1, it will only get rid of the fixture.  Body_1 will remain.

If you want to get rid of a body, you use the RemoveBody() method of the World object.