load static method

Future<TiledComponent<FlameGame<World>>> load(
  1. String fileName,
  2. Vector2 destTileSize, {
  3. double? atlasMaxX,
  4. double? atlasMaxY,
  5. String prefix = 'assets/tiles/',
  6. int? priority,
  7. bool? ignoreFlip,
  8. AssetBundle? bundle,
  9. Images? images,
  10. bool tsxPackingFilter(
    1. Tileset
    )?,
  11. bool useAtlas = true,
  12. Paint layerPaintFactory(
    1. double opacity
    )?,
  13. double atlasPackingSpacingX = 0,
  14. double atlasPackingSpacingY = 0,
})

Loads a TiledComponent from a file.

This method looks for files under the path "assets/tiles/" by default. This can be changed by providing a different path to prefix.

By default, RenderableTiledMap renders flipped tiles if they exist. You can disable it by passing ignoreFlip as true.

A custom atlasMaxX and atlasMaxY can be provided in case you want to change the max size of TiledAtlas that TiledComponent creates internally.

TiledComponent uses Flame's SpriteBatch to render the map. Which under the hood uses Canvas.drawAtlas calls to render the tiles. This behavior can be changed by setting useAtlas to false. This will make the map be rendered with Canvas.drawImageRect calls instead.

Implementation

static Future<TiledComponent> load(
  String fileName,
  Vector2 destTileSize, {
  double? atlasMaxX,
  double? atlasMaxY,
  String prefix = 'assets/tiles/',
  int? priority,
  bool? ignoreFlip,
  AssetBundle? bundle,
  Images? images,
  bool Function(Tileset)? tsxPackingFilter,
  bool useAtlas = true,
  Paint Function(double opacity)? layerPaintFactory,
  double atlasPackingSpacingX = 0,
  double atlasPackingSpacingY = 0,
}) async {
  return TiledComponent(
    await RenderableTiledMap.fromFile(
      fileName,
      destTileSize,
      atlasMaxX: atlasMaxX,
      atlasMaxY: atlasMaxY,
      ignoreFlip: ignoreFlip,
      prefix: prefix,
      bundle: bundle,
      images: images,
      tsxPackingFilter: tsxPackingFilter,
      useAtlas: useAtlas,
      layerPaintFactory: layerPaintFactory,
      atlasPackingSpacingX: atlasPackingSpacingX,
      atlasPackingSpacingY: atlasPackingSpacingY,
    ),
    priority: priority,
  );
}