destroy method

void destroy(
  1. Contact c
)

Implementation

void destroy(Contact c) {
  Fixture fixtureA = c.fixtureA;
  Fixture fixtureB = c.fixtureB;
  Body bodyA = fixtureA.getBody();
  Body bodyB = fixtureB.getBody();

  if (contactListener != null && c.isTouching()) {
    contactListener.endContact(c);
  }

  // Remove from the world.
  if (c._prev != null) {
    c._prev._next = c._next;
  }

  if (c._next != null) {
    c._next._prev = c._prev;
  }

  if (c == contactList) {
    contactList = c._next;
  }

  // Remove from body 1
  if (c._nodeA.prev != null) {
    c._nodeA.prev.next = c._nodeA.next;
  }

  if (c._nodeA.next != null) {
    c._nodeA.next.prev = c._nodeA.prev;
  }

  if (c._nodeA == bodyA._contactList) {
    bodyA._contactList = c._nodeA.next;
  }

  // Remove from body 2
  if (c._nodeB.prev != null) {
    c._nodeB.prev.next = c._nodeB.next;
  }

  if (c._nodeB.next != null) {
    c._nodeB.next.prev = c._nodeB.prev;
  }

  if (c._nodeB == bodyB._contactList) {
    bodyB._contactList = c._nodeB.next;
  }

  // Call the factory.
  _pool.pushContact(c);
  --contactCount;
}