onGameResize method

  1. @override
  2. @mustCallSuper
void onGameResize(
  1. Vector2 canvasSize
)
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 canvasSize) {
  if (!isMounted) {
    // TODO(st-pasha): remove this hack, which is for test purposes only
    setMounted();
  }
  camera.handleResize(canvasSize);
  super.onGameResize(canvasSize); // Game.onGameResize
  // [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(canvasSize);
}