onGameResize method
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.
Implementation
@override
@mustCallSuper
void onGameResize(Vector2 size) {
super.onGameResize(size);
// This work-around is needed since the camera has the highest priority and
// [size] uses [viewport.virtualSize], so the viewport needs to be updated
// first since users will be using `game.size` in their [onGameResize]
// methods.
camera.viewport.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));
}