Instead of rendering tiled map as usual:
final mapComponent = await TiledComponent.load('map.tmx', Vector2.all(16));
world.add(mapComponent);
convert it into special component:
final mapComponent = await TiledComponent.load('map.tmx', Vector2.all(16));
final imageCompiler = ImageBatchCompiler();
final ground = imageCompiler.compileMapLayer(tileMap: mapComponent.tileMap, layerNames: ['ground']);
ground.priority = RenderPriority.ground.priority;
world.add(ground);
The layerNames
variable allows you to specify layers to convert. It is useful when different map
layers should have different priorities.
If you need to process each tile individually - use TileProcessor
:
final mapComponent = await TiledComponent.load('map.tmx', Vector2.all(16));
TileProcessor.processTileType(
tileMap: mapComponent.tileMap,
processorByType: <String, TileProcessorFunc>{
'water': ((tile, position, size) {
/// Create here a new object, save tile data or process it
/// a way your game logics need
}),
},
layersToLoad: [
'water',
]);
The first parameter of TileProcessorFunc
is instance of TileProcessor
class.
Use instance of TileProcessor
inside of TileProcessorFunc
to access all necessary data:
tile.getSprite()
to get Sprite
object of the tiletile.getSpriteAnimation()
to get SpriteAnimation
object of the tile. It brings tiled support
of animated map - missing but strongly required featuretile.getCollisionRect()
allows to load RectangleHitbox
, if collision rect was specified in
Tiled editor. The library only supports rectangular shapes. It is cheaper to merge multiple small animated tiles into big one, then render each tile with same animation.
This could be achieved by combining TileProcessor.processTileType
and AnimationBatchCompiler
:
final mapComponent = await TiledComponent.load('map.tmx', Vector2.all(16));
final animationCompiler = AnimationBatchCompiler();
TileProcessor.processTileType(
tileMap: tiledComponent.tileMap,
processorByType: <String, TileProcessorFunc>{
'water': ((tile, position, size) {
animationCompiler.addTile(position, tile);
}),
},
layersToLoad: [
'water',
]);
final animatedWater = await animationCompiler.compile();
animatedWater.priority = RenderPriority.water.priority;
world.add(animatedWater);