onViewportResize method

  1. @override
void onViewportResize()
override

Called after the size of the viewport has changed.

The new size will be stored in the size property. This method could be invoked either when the user explicitly changes the size of the viewport, or when the size changes automatically in response to the change in game canvas size.

A typical implementation would need to adjust the viewport's clip mask to match the new size.

Implementation

@override
void onViewportResize() {
  final desiredWidth = size.y * aspectRatio;
  if (desiredWidth > size.x) {
    size.y = size.x / aspectRatio;
  } else {
    size.x = desiredWidth;
  }

  final x = size.x / 2;
  final y = size.y / 2;
  _clipRect = Rect.fromLTRB(-x, -y, x, y);
}