fledge_tiled library
Tiled tilemap support for the Fledge ECS game framework.
This library provides full integration with Tiled, a popular 2D tilemap editor. It supports:
- TMX/TSX Parsing: Load Tiled maps and external tilesets
- Tile Layers: Efficient rendering with atlas batching
- Object Layers: Spawn entities from Tiled objects
- Animated Tiles: Automatic tile animation support
- Collision Shapes: Generate collision from objects and tiles
- Custom Properties: Type-safe access to Tiled properties
- Infinite Maps: Chunk-based loading for large maps
Quick Start
import 'package:fledge_ecs/fledge_ecs.dart';
import 'package:fledge_tiled/fledge_tiled.dart';
void main() async {
final app = App()
.addPlugin(WallTimePlugin())
.addPlugin(TiledPlugin());
// Load a tilemap
final loader = AssetTilemapLoader(
loadStringContent: (path) => rootBundle.loadString(path),
);
final tilemap = await loader.load(
'assets/maps/level1.tmx',
(path, w, h) async => await loadTexture(path),
);
// Store and spawn
app.world.getResource<TilemapAssets>()!.put('level1', tilemap);
app.world.eventWriter<SpawnTilemapEvent>().send(
SpawnTilemapEvent(assetKey: 'level1'),
);
await app.run();
}
Object Spawning
Objects from Tiled can be spawned as entities with custom components:
SpawnTilemapEvent(
assetKey: 'level1',
config: TilemapSpawnConfig(
tileConfig: TileLayerConfig(
generateColliders: true,
colliderLayers: {'Collision'},
),
objectTypes: {
'enemy': ObjectTypeConfig(
onSpawn: (entity, obj) {
entity.insert(Enemy(
health: obj.properties.getIntOr('health', 100),
));
},
),
'collectible': ObjectTypeConfig(
createCollider: false,
onSpawn: (entity, obj) {
entity.insert(Collectible(
value: obj.properties.getIntOr('value', 10),
));
},
),
},
),
)
Classes
- AssetTilemapLoader
- Loader for tilemaps bundled as Flutter assets or loaded from strings.
- ChunkKey
- Key for identifying chunks in infinite maps.
- Collider
- Component containing collision shapes.
- CollisionConfig
- Configuration for collision behavior.
- CollisionDetectionSystem
- Detects collisions between entities and writes CollisionEvents to the ECS event queue.
- CollisionEvent
- Event published when two entities collide.
- CollisionGrid
- A 2D grid representing walkability for pathfinding.
- CollisionLayers
- Base collision layer definitions.
- CollisionResolutionSystem
- Adjusts velocity to prevent movement into solid colliders.
- CollisionShape
- Base class for collision shapes from Tiled.
- CulledTilemapExtractor
- Camera-aware tilemap extractor that culls tiles at extraction time.
- EllipseShape
- An ellipse collision shape.
- ExtractedTile
- Extracted tile data for the render world.
- LoadedTilemap
- A fully loaded tilemap with all required resources.
- LoadedTileset
- A loaded tileset with texture and metadata.
- ObjectLayer
- Component for object layers from Tiled.
- ObjectTypeConfig
- Configuration for spawning a specific object type.
- Pathfinder
- A* pathfinding for tile-based maps.
- PathResult
- Result of a pathfinding operation.
- PhysicsConfig
- Configuration for the physics plugin.
- PhysicsPlugin
- Physics and collision handling plugin.
- PointShape
- A point collision shape.
- PolygonShape
- A polygon collision shape.
- PolylineShape
- A polyline collision shape (open path).
- RectangleShape
- A rectangle collision shape.
- SpatialHash
-
Uniform-grid spatial hash used by
CollisionDetectionSystemto cut broad-phase pair generation from O(n^2) down to O(n) for well-spread scenes. - SpawnTilemapEvent
- Event to spawn a tilemap in the world.
- TileAnimation
- Animation data for a single animated tile.
- TileAnimationFrame
- A single frame in a tile animation.
- TileAnimationSystem
- System that updates tile animations.
- TileChunk
- Chunk data for infinite maps.
- TileCollider
- Utility for generating collision shapes from Tiled data.
- TileCollisionData
- Data for a tile with collision.
- TiledAnimationFrame
- Intermediate representation of Tiled animation frame data.
- TileData
- Pre-computed tile data for a single tile.
- TiledContentProvider
- Provider for loading TMX/TSX content from different sources.
- TiledObject
- Component attached to entities spawned from Tiled objects.
- TiledObjectData
- Normalized object data from Tiled.
- TiledPlugin
- Plugin that adds Tiled tilemap support to Fledge.
- TiledPluginConfig
- Configuration for the Tiled plugin.
- TiledProperties
- Type-safe wrapper for Tiled custom properties.
- TileLayer
- Component for a single tile layer.
- TileLayerConfig
- Configuration for tile layer spawning.
- Tilemap
- Root component representing a complete Tiled map.
- TilemapAnimator
- Component tracking animated tiles for a tilemap.
- TilemapAssets
- Resource managing loaded tilemap assets.
- TilemapExtractor
- Extractor for tilemap layers.
- TilemapLoader
- Abstract interface for loading tilemaps from various sources.
- TilemapSpawnConfig
- Configuration for tilemap spawning.
- TilemapSpawnedEvent
- Event fired when a tilemap is spawned.
- TilemapSpawnSystem
- System that spawns entities from loaded tilemaps.
- TilesetLookup
- Result of looking up a tileset for a GID.
- TilesetRegistry
- Resource for managing shared tilesets across multiple maps.
- TmxLoader
-
A
Loaderthat reads a.tmxtilemap from a path. - TsxLoader
-
A
Loaderthat reads a.tsxexternal tileset from a path. - Velocity
- Component representing an entity's velocity.
Enums
- DrawOrder
- Draw order for objects in an object layer.
- ObjectShape
- Shape types for Tiled objects.
- RenderOrder
- Render order for tiles in the map.
Functions
-
extractCollisionGrid(
LoadedTilemap tilemap, {Set< String> collisionLayers = const {'Collision', 'collision'}}) → CollisionGrid - Extracts a CollisionGrid from a LoadedTilemap.
-
extractCollisionGridFromTmx(
String tmxContent, {required int mapWidth, required int mapHeight, Set< String> collisionLayers = const {'Collision', 'collision'}}) → CollisionGrid - Extracts a CollisionGrid directly from TMX content.
-
extractCollisionGrids(
Map< String, LoadedTilemap> tilemaps, {Set<String> collisionLayers = const {'Collision', 'collision'}}) → Map<String, CollisionGrid> - Extracts collision grids from multiple tilemaps.
Typedefs
-
TextureLoader
= Future<
TextureHandle> Function(String path, int width, int height) - Callback for loading textures.
- TilemapAsset = LoadedTilemap
-
The value type stored in
Assets<TilemapAsset>— a parsed.tmxtilemap plus every tileset it references. - TilesetAsset = LoadedTileset
-
The value type stored in
Assets<TilesetAsset>— a parsed.tsxtileset plus its texture atlas.