setActive method

void setActive (bool flag)

Set the active state of the body. An inactive body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will be destroyed. Fixtures and joints are otherwise unaffected. You may continue to create/destroy fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive body are implicitly inactive. An inactive body is still owned by a World object and remains in the body list.

@param flag

Implementation

void setActive(bool flag) {
  assert(world.isLocked() == false);

  if (flag == isActive()) {
    return;
  }

  if (flag) {
    _flags |= ACTIVE_FLAG;

    // Create all proxies.
    BroadPhase broadPhase = world._contactManager.broadPhase;
    for (Fixture f = _fixtureList; f != null; f = f._next) {
      f.createProxies(broadPhase, _transform);
    }

    // Contacts are created the next time step.
  } else {
    _flags &= ~ACTIVE_FLAG;

    // Destroy all proxies.
    BroadPhase broadPhase = world._contactManager.broadPhase;
    for (Fixture f = _fixtureList; f != null; f = f._next) {
      f.destroyProxies(broadPhase);
    }

    // Destroy the attached contacts.
    ContactEdge ce = _contactList;
    while (ce != null) {
      ContactEdge ce0 = ce;
      ce = ce.next;
      world._contactManager.destroy(ce0.contact);
    }
    _contactList = null;
  }
}