onLoad method

  1. @override
Future<void>? onLoad()

Whenever onLoad returns something, the parent will wait for the Future to be resolved before adding it. If null is returned, the class is added right away.

The default implementation just returns null.

This can be overwritten to add custom logic to the component loading.

Example:

@override
Future<void> onLoad() async {
  myImage = await gameRef.load('my_image.png');
}

Implementation

@override
Future<void>? onLoad() async {
  imageSprite = await MapAssetsManager.getFutureSprite(imagePath);
  position = Rect.fromLTWH(
          offset.x,
          offset.y,
          imageSprite!.image.width * factor,
          imageSprite!.image.height * factor)
      .toVector2Rect();
  return super.onLoad();
}