addTiles method

void addTiles(
  1. List<Tile> tiles
)

Adds many tiles at once (used by infinite maps when a new chunk loads).

Grows the quad tree when a tile falls outside its current bounds, so chunks can be spawned at arbitrary (including negative) coordinates.

Implementation

void addTiles(List<Tile> tiles) {
  if (tiles.isEmpty) {
    return;
  }
  _tiles.addAll(tiles);
  final grew = _growQuadTreeToFit(tiles);
  if (!grew) {
    for (final tile in tiles) {
      _quadTree?.insert(
        tile,
        Point(tile.x, tile.y),
        id: tile.id,
      );
    }
  }
  // Differential update: only add the newly visible tiles and remove the
  // ones that are no longer visible — no full rebuild (cheap on chunk load).
  onMoveCamera(_lastRectCamera);
}