findGame method

FlameGame<World>? findGame()
inherited

Fetches the nearest FlameGame ancestor to the component.

Implementation

FlameGame? findGame() {
  assert(
    staticGameInstance is FlameGame || staticGameInstance == null,
    'A component needs to have a FlameGame as the root.',
  );
  final gameInstance = staticGameInstance is FlameGame
      ? staticGameInstance! as FlameGame
      : null;
  return gameInstance ??
      ((this is FlameGame) ? (this as FlameGame) : _parent?.findGame());
}