size property

  1. @override
Vector2 size
override

Size of the viewport, i.e. its width and height.

This property represents the bounding box of the viewport. If the viewport is rectangular in shape, then size describes the dimensions of that rectangle. If the viewport has any other shape (for example, circular), then size describes the dimensions of the bounding box of the viewport.

Changing the size at runtime triggers the onViewportResize event. The size cannot be negative.

Implementation

@override
Vector2 get size {
  if (!_isInitialized && camera.parent is FlameGame) {
    // This is so that the size can be accessed before the viewport is fully
    // mounted.
    onGameResize((camera.parent! as FlameGame).canvasSize);
  }
  return _size;
}
  1. @override
void size=(Vector2 value)
override

Implementation

@override
set size(Vector2 value) {
  assert(
    value.x >= 0 && value.y >= 0,
    "Viewport's size cannot be negative: $value",
  );
  _size.setFrom(value);
  _isInitialized = true;
  if (parent != null) {
    camera.viewfinder.onViewportResize();
  }
  onViewportResize();
  if (hasChildren) {
    children.forEach((child) => child.onParentResize(_size));
  }
}