setActive method
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.
Implementation
void setActive(bool flag) {
assert(!world.isLocked);
if (flag == isActive) {
return;
}
if (flag) {
flags |= activeFlag;
// Create all proxies.
final broadPhase = world.contactManager.broadPhase;
for (final f in fixtures) {
f.createProxies(broadPhase, transform);
}
// Contacts are created the next time step.
} else {
flags &= ~activeFlag;
// Destroy all proxies.
final broadPhase = world.contactManager.broadPhase;
for (final f in fixtures) {
f.destroyProxies(broadPhase);
}
// Destroy the attached contacts.
while (contacts.isNotEmpty) {
world.contactManager.destroy(contacts.first);
}
contacts.clear();
}
}