prepare method

  1. @mustCallSuper
void prepare(
  1. Component parent
)

Prepares the Component to be added to a parent, and if there is an ancestor that is a FlameGame that game will do necessary preparations for this component. If there are no parents that are a Game false will be returned and this will run again once an ancestor or the component itself is added to a Game.

Implementation

@mustCallSuper
void prepare(Component parent) {
  _parent = parent;

  final parentGame = findParent<FlameGame>();
  if (parentGame == null) {
    isPrepared = false;
  } else {
    assert(
      parentGame.hasLayout,
      '"prepare/add" called before the game is ready. '
      'Did you try to access it on the Game constructor? '
      'Use the "onLoad" or "onMount" method instead.',
    );
    if (parentGame is FlameGame) {
      parentGame.prepareComponent(this);
    }

    debugMode |= parent.debugMode;
    isPrepared = true;
  }
}