removeBody method

  1. @override
void removeBody(
  1. PhysicsBody body
)
override

Remove a physics body, and the joints that hold it. The contacts and overlaps it was in end without an event, as on the native backend.

Implementation

@override
void removeBody(PhysicsBody body) {
  if (!_nativeReady) {
    super.removeBody(body);
    return;
  }
  final b2Body = _bodyMap.remove(body);
  if (b2Body == null) return;
  _handleToBody.remove(b2Body.handle);
  _pushed.remove(body);
  // Box2D destroys the body's joints with it; they, and the Dart joints on
  // it, leave [joints] too.
  for (final joint in joints) {
    final pair = _jointBodies[joint];
    final holds = pair != null
        ? pair.$1 == body || pair.$2 == body
        : joint.bodies.contains(body);
    if (holds) removeJoint(joint);
  }
  b2Body.destroy();
}