fromTiledMap static method
Future<RenderableTiledMap>
fromTiledMap(
- TiledMap map,
- Vector2 destTileSize, {
- double? atlasMaxX,
- double? atlasMaxY,
- CameraComponent? camera,
- bool? ignoreFlip,
- Images? images,
- AssetBundle? bundle,
- bool tsxPackingFilter()?,
- bool useAtlas = true,
- Paint layerPaintFactory(
- double opacity
- double atlasPackingSpacingX = 0,
- 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,
);
}