add method

  1. @override
Future<void> add(
  1. Component component
)
override

Prepares and registers a component to be added on the next game tick

This method is an async operation since it await the onLoad method of the component. Nevertheless, this method only need to be waited to finish if by some reason, your logic needs to be sure that the component has finished loading, otherwise, this method can be called without waiting for it to finish as the FlameGame already handle the loading of the component.

Note: Do not add components on the game constructor. This method can only be called after the game already has its layout set, this can be verified by the Game.hasLayout property, to add components upon game initialization, the onLoad method can be used instead.

Implementation

@override
Future<void> add(Component component) {
  if (component is BonfireHasGameRef) {
    (component as BonfireHasGameRef).gameRef = gameRef;
  }
  return super.add(component);
}