onComponentTypeCheck method

  1. @override
  2. @mustCallSuper
bool onComponentTypeCheck(
  1. PositionComponent other
)
override

Defines whether the other component should be able to collide with this component.

If the hitboxParent is not CollisionCallbacks but PositionComponent, there is no CollisionCallbacks.onComponentTypeCheck in that component. As a result, it will always be able to collide with all other types.

Implementation

@override
@mustCallSuper
bool onComponentTypeCheck(PositionComponent other) {
  final otherHitboxParent = (other as ShapeHitbox).hitboxParent;

  final thisCanCollideWithOther = (hitboxParent is! CollisionCallbacks) ||
      (hitboxParent as CollisionCallbacks)
          .onComponentTypeCheck(otherHitboxParent);

  final otherCanCollideWithThis =
      (otherHitboxParent is! CollisionCallbacks) ||
          (otherHitboxParent as CollisionCallbacks)
              .onComponentTypeCheck(hitboxParent);

  return thisCanCollideWithOther && otherCanCollideWithThis;
}