Remove Body

Topics: User Forum
Sep 15, 2011 at 9:18 PM

I'm doing a test with the farseer and I'm having trouble removing bodies.

World world;
Body ground;
Body box1;
Body box2;
List<Body> blocks;

ground = BodyFactory.CreateEdge(world, ConvertUnits.ToMeter(new Vector2(0, 480)), ConvertUnits.ToMeter(new Vector2(800, 480)));
ground.BodyType = BodyType.Kinematic;

box1 = BodyFactory.CreateRectangle(world, ConvertUnits.ToMeter(texture.Width), ConvertUnits.ToMeter(texture.Height), 1, ConvertUnits.ToMeter(new Vector2(420, 400)));
box1.BodyType = BodyType.Dynamic;
box1.Friction = 0.6f;
box1.Restitution = 0.4f;

box2 = BodyFactory.CreateRectangle(world, ConvertUnits.ToMeter(texture.Width), ConvertUnits.ToMeter(texture.Height), 1, ConvertUnits.ToMeter(new Vector2(420, 340)));
box2.BodyType = BodyType.Dynamic;
box2.Friction = 0.6f;
box2.Restitution = 0.4f;

blocks.Add(box1);
blocks.Add(box2);

...

// In Update

world.Step(1f / 30f);
RemoveBlocks();


// In RemoveBlocks

TouchCollection touches = TouchPanel.GetState();
if (touches.Count > 0)
{
    Vector2 touchPoint = ConvertUnits.ToMeter(new Vector2(touches[0].Position.X, touches[0].Position.Y));

    for (int i = blocks.Count - 1; i >= 0; i--)
    {
        if( blocks[i].FixtureList[0].TestPoint(ref touchPoint))
        {
            world.RemoveBody(blocks[i]);
        }
    }
} 

When I touch on the box1, it is removed, but the box2 does not fall.

Sep 17, 2011 at 6:41 PM

didn't tested it but i think box2 is still sleeping.

Sep 17, 2011 at 6:52 PM

Thank you!

body.SleepingAllowed = false;

Sep 17, 2011 at 6:58 PM

better just wake every body up after you removed a body

Sep 17, 2011 at 6:58 PM
Edited Sep 17, 2011 at 6:59 PM

double post... where is the remove buton D: