visibleWorldRect property

Rect get visibleWorldRect

The axis-aligned bounding rectangle of a world region which is currently visible through the viewport.

This property can be useful in order to determine which components within the game's world are currently visible to the player, and which aren't.

If the viewport is non-rectangular, or if the world's view is rotated, then the visibleWorldRect will be larger than the actual viewing area. Thus, this property is "conservative": everything outside of this rect is definitely not visible, while the points inside may or may not be visible.

This property is cached, and is recalculated whenever the camera moves or the viewport is resized. At the same time, it may only be accessed after the camera was fully mounted.

Implementation

Rect get visibleWorldRect {
  assert(
    parent != null,
    "This property can't be accessed before the camera is added to the game. "
    'If you are using visibleWorldRect from another component (for example '
    'the World), make sure that the CameraComponent is added before that '
    'Component.',
  );
  return viewfinder.visibleWorldRect;
}