Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have many sensors(coins) in each level and I want to remove the sensors(coins) when the player rectangle(Mario) touches them. I check in OnCollision if Mario touches a coin, if he touches it, it should be removed. But I don't know how to remove a body.

What is the best way to remove a body?

How can I remove a coin in this example?

bool Player_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
    {
      if (fixtureB.CollisionCategories == Category.Cat10)
        {

        }
        return true;
    }

 coinrect = BodyFactory.CreateRectangle(world, 0.64f, 0.64f, 1.0f);
 coinrect.BodyType = BodyType.Static;
 coinrect.Position = new Vector2(1.60f, 4.16f);
 coinrect.CollisionCategories = Category.Cat10;

 coinrect2 = BodyFactory.CreateRectangle(world, 0.64f, 0.64f, 1.0f);
 coinrect2.BodyType = BodyType.Static;
 coinrect2.Position = new Vector2(2.60f, 3.16f);
 coinrect2.CollisionCategories = Category.Cat10;

 playerrect = BodyFactory.CreateRectangle(world, 0.64f, 0.64f, 1.0f);
 playerrect.BodyType = BodyType.Dynamic;
 playerrect.Position = new Vector2(0.22f, 0f);
 playerrect.FixedRotation = true;

 playerrect.OnCollision += Player_OnCollision; 
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Body.Dispose(bodyhere) is what you are looking for. It removes the body as well as all attached features. If you do not want to move Body.Dispose you can use World.RemoveBody(bodyhere) which removes the body after the current step. I would recommend you use the latter though.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.