Box 2d How To Destroy Boxes

Currently I'm trying to remove a box from the world in processing. I've managed to make the box vanish but still exist while staying invisible. If anyone knows how to fix this I'd greatly appricate the help.

void beginContact(Contact cp)
{
  Fixture fd = cp.getFixtureA();
  Fixture fd2 = cp.getFixtureB();

  Body bd = fd.getBody();
  Body bd2 = fd2.getBody();
  Object p = bd.getUserData();
  Object b = bd2.getUserData();

if(p.getClass() == Box.class && b.getClass() == Box.class)
  {
    Box p1 = (Box) p;
    Box p2 = (Box) b;
    if(p1.getPlayer() == 3)
    {
      //boxes.remove(p1);
      //p1.killBody();
    }
    else if(p2.getPlayer() == 3)
    {
      //boxes.remove(p2);
      //p2.killBody(); 
    }

    if(p1.getPlayer() == 1)
    {
      jump = true;
    }

    else if(p2.getPlayer() == 1)
    {
      jump = true;
    }
  }
}

void endContact(Contact cp)
{
  Fixture fd = cp.getFixtureA();
  Fixture fd2 = cp.getFixtureB();

  Body bd = fd.getBody();
  Body bd2 = fd2.getBody();
  Object p = bd.getUserData();
  Object b = bd2.getUserData();

if(p.getClass() == Box.class && b.getClass() == Box.class)
  {
    Box p1 = (Box) p;
    Box p2 = (Box) b;

    if(p1.getPlayer() == 1)
    {
      jump = false;
    }

    else if(p2.getPlayer() == 1)
    {
      jump = false;
    }
  }
}

//Credits
//http://suvitruf.ru/2012/12/10/2672/
//https://github.com/shiffman/Box2D-for-Processing/blob/master/Box2D-for-Processing/dist/box2d_processing/examples/CollisionListeningDeletionExercise/CollisionListeningDeletionExercise.pde

Answers

Sign In or Register to comment.