fromTiledMap static method

Future<RenderableTiledMap> fromTiledMap(
  1. TiledMap map,
  2. Vector2 destTileSize, {
  3. double? atlasMaxX,
  4. double? atlasMaxY,
  5. CameraComponent? camera,
  6. bool? ignoreFlip,
  7. Images? images,
  8. AssetBundle? bundle,
  9. bool tsxPackingFilter(
    1. Tileset
    )?,
  10. bool useAtlas = true,
  11. Paint layerPaintFactory(
    1. double opacity
    )?,
  12. double atlasPackingSpacingX = 0,
  13. double atlasPackingSpacingY = 0,
})

Parses a TiledMap returning a RenderableTiledMap.

By default, FlameTileLayer renders flipped tiles if they exist. You can disable this by setting ignoreFlip to true.

Implementation

static Future<RenderableTiledMap> fromTiledMap(
  TiledMap map,
  Vector2 destTileSize, {
  double? atlasMaxX,
  double? atlasMaxY,
  CameraComponent? camera,
  bool? ignoreFlip,
  Images? images,
  AssetBundle? bundle,
  bool Function(Tileset)? tsxPackingFilter,
  bool useAtlas = true,
  Paint Function(double opacity)? layerPaintFactory,
  double atlasPackingSpacingX = 0,
  double atlasPackingSpacingY = 0,
}) async {
  // We're not going to load animation frames that are never referenced; but
  // we do supply the common cache for all layers in this map, and maintain
  // the update cycle for these in one place.
  final animationFrames = <Tile, TileFrames>{};

  // While this _should_ not be needed - it is possible have tilesets out of
  // order and Tiled won't complain, but we'll fail.
  map.tilesets.sort((l, r) => (l.firstGid ?? 0) - (r.firstGid ?? 0));

  final renderableLayers = await _renderableLayers(
    map.layers,
    null,
    map,
    destTileSize,
    camera,
    animationFrames,
    atlas: await TiledAtlas.fromTiledMap(
      map,
      maxX: atlasMaxX,
      maxY: atlasMaxY,
      images: images,
      tsxPackingFilter: tsxPackingFilter,
      useAtlas: useAtlas,
      spacingX: atlasPackingSpacingX,
      spacingY: atlasPackingSpacingY,
    ),
    ignoreFlip: ignoreFlip,
    images: images,
    layerPaintFactory: layerPaintFactory ?? _defaultLayerPaintFactory,
  );

  return RenderableTiledMap(
    map,
    renderableLayers,
    destTileSize,
    camera: camera,
    animationFrames: animationFrames,
  );
}