seeComponent method

void seeComponent(
  1. GameComponent component, {
  2. required dynamic observed(
    1. GameComponent
    ),
  3. VoidCallback? notObserved,
  4. double radiusVision = 32,
})

This method we notify when detect the component when enter in radiusVision configuration Method that bo used in update method.

Implementation

void seeComponent(
  GameComponent component, {
  required Function(GameComponent) observed,
  VoidCallback? notObserved,
  double radiusVision = 32,
}) {
  if (component.shouldRemove) {
    notObserved?.call();
    return;
  }

  Rect fieldOfVision = Rect.fromCircle(
    center: this.center.toOffset(),
    radius: radiusVision,
  );

  if (fieldOfVision.overlaps(getRectAndCollision(component))) {
    observed(component);
  } else {
    notObserved?.call();
  }
}