onGameResize method

  1. @override
  2. @mustCallSuper
void onGameResize(
  1. Vector2 size
)
inherited

This passes the new size along to every component in the tree via their Component.onGameResize method, enabling each one to make their decision of how to handle the resize event.

It also updates the size field of the class to be used by later added components and other methods. You can override it further to add more custom behavior, but you should seriously consider calling the super implementation as well. This implementation also uses the current camera in order to transform the coordinate system appropriately.

Implementation

@override
@mustCallSuper
void onGameResize(Vector2 size) {
  camera.handleResize(size);
  super.onGameResize(size);
  // [onGameResize] is declared both in [Component] and in [Game]. Since
  // there is no way to explicitly call the [Component]'s implementation,
  // we propagate the event to [FlameGame]'s children manually.
  handleResize(size);
  children.forEach((child) => child.onParentResize(size));
}