just_tiled 0.4.1
just_tiled: ^0.4.1 copied to clipboard
Read and write Tiled Map Editor files (TMX, TSX, TMJ, TSJ) and draw their tile layers in Flutter: every orientation, infinite maps, every encoding.
Changelog #
0.4.1 - 2026-10-15 #
Fixed #
- Flipped and turned tiles drew wrong.
TileMapRenderermirrored a tile by reversing its source rectangle, whichdrawRawAtlasdoesn't do: a mirrored tile drew unmirrored, a tile away from its cell, and the diagonal flips D+H and D+V turned the wrong way. Every flip and turn now draws as in Tiled, still in one call per layer. A layer with mirrored tiles draws from the newTextureAtlas.mirroredImage: the tileset image with a mirrored copy beside it. - Tiles are placed as Tiled places them. A tile larger than the grid stands on its cell's bottom-left corner, moved by the tileset's
tileOffset; it was drawn from the cell's top-left. Isometric tiles were drawn half a tile to the right. - Culling works for every orientation, not only orthogonal layers of over 10,000 cells. It no longer builds new buffers every frame, keeps the layer's tint (culled layers lost it), and still draws in one call.
drawRawAtlasgets the tiles' bounds as its cull rectangle, not the view. DefaultTsxProvidercollapses.and.., so a tileset in a folder beside the map's (../tilesets/terrain.tsx) loads.basePathis the map's folder.- A template's tile object kept the template's tile number. A template numbers its tile from its own tileset; the gid is now renumbered to the map's first gid for that tileset, flags kept.
- Properties of Tiled's custom types (1.8+) lost their type. A property's
propertytype, the enum's or class's name, is now read and written back. Aclassproperty's members were read as a whitespace string and written back as one; they are now nestedTiledProperties, written back as members. - Broken TMJ and TSJ files threw
TypeError. They now throwFormatException, as broken TMX files do, andTmjParser.parsereports invalid JSON through its future rather than throwing at once. - Zstandard tile data could be read wrong without an error. The Zstandard decoder (
just_zstd0.2.0) reads only uncompressed blocks and returns wrong bytes for compressed ones. Zstandard data must now unpack to exactly its layer's or chunk's tiles, or throwsFormatException. SpatialHashGrid: inserting an item again left a stale copy at its old place, which queries kept finding. A query the size of the world, or an item that large, walked every cell inside it; both are now checked directly. Bounds that aren't finite throwArgumentError.- Polygon and polyline points separated by any whitespace, not just single spaces, are read.
Added #
TileMapRendererdraws infinite maps' chunked layers, draws an orthogonal map's tiles in its render order, and reportstileCount.TextureAtlas.mirroredImageandgetMirroredSourceRect.TiledProperties.propertyTypeOfandgetClass; aTiledPropertiesconstructor argument for custom types.DefaultTsxProvider.resolve, the asset key a path from the map loads from.- Documentation for every public member, and pubspec topics.
Changed #
- zlib and gzip now come from
just_deflate, a pure Dart package with no dependencies. Thearchivepackage, and with itpathandposix, is gone. Maps read and write as before. Compressed output is about the same size, but the bytes differ fromarchive's. - Compressed tile data may not unpack to more than its layer's or chunk's
width × heightids. Damaged or hostile data now throwsFormatExceptionrather than filling memory. xmlmay be 6.5 to 7.x. The Flutter floor is 3.41.0, the first with Dart 3.11, which the package already needed.- The code is
dart formatted.
Tests #
- 136 in all. New: the renderer drawn into images (every flip and turn, tall tiles and offsets, isometric, chunks, culling against drawing everything in each orientation, tint, render order, the mirrored image), asset paths through a mocked bundle, templates, custom-type properties through every reader and writer, broken files, Zstandard, and the spatial grid at its edges. The renderer tests fail on 0.4.0's renderer.
0.4.0 - 2026-10-04 #
Added #
- Writers.
TmxWriter.write(map, encoding:)(CSV, base64, base64+zlib, base64+gzip) andTsxWriter.write(tileset)produce TMX 1.10 documents the Tiled editor opens:typeon tiles and objects,classelsewhere, a tileset with asourcewritten as a reference to its external file. - Tiled's JSON formats.
TmjParser/TmjWriterread and write TMJ maps and TSJ tilesets into the same models. A TMX map may now refer to a.tsjtileset, and a TMJ map to a.tsxone. - Infinite maps.
TileLayer.chunks(TileChunk{x, y, width, height, data}) andTileLayer.isChunked. - Raw ids.
TileLayer.rawDatakeeps every flag, including the hexagonal 120° one;rawGidAt/rawGids.TiledGidholds the flag constants and helpers (idOf,flagsOf,compose,fromBytes,toBytes) — unsigned throughout, so they behave the same on the web. - Wang sets.
Tileset.wangSets(WangSet,WangColor,WangSetTypecorner / edge / mixed), including Tiled's pre-1.5 hex Wang ids (TileMapParser.parseWangId). - Tileset
className,objectAlignment,tileRenderSize,fillMode,grid,transformations,isImageCollection; layerclassNameandlocked; image layerrepeatX/repeatYand image size; mapclassNameandparallaxOriginX/parallaxOriginY. TiledPropertiesremembers each property's declared type (typeOf), so afileorobjectproperty is written back as one.TileMapParser.parseTilesetreads a standalone TSX document.
Fixed #
- Infinite maps were read as nonsense. The parser read the whole
<data>text as one list, running every<chunk>together. - The hexagonal 120° rotation flag was left inside the tile id. The id mask is now
0x0FFFFFFF; the flag is kept inrawData.
Tests #
- 47 more: fixtures in Tiled 1.10's own form for every orientation, finite and infinite, every encoding and flip, Wang sets of each kind, external TSX and TSJ, each round-tripped through every writer (93 total).
0.3.0 - 2026-04-22 #
Breaking #
Layer.parallelX/parallelYrenamed toparallaxX/parallaxY.
Fixed #
TileMapRenderer: corrected H/V/diagonal tile flip logic in bothcompile()and_renderCulled();_tileCountnow reflects actual compiled tiles.TileMapParser: template-load errors now logged in debug mode instead of silently swallowed;_parsePointsStringusestryParseto avoid crashes on malformed data;_mergeTemplateObjectrespects the Tiled 1.9+classattribute on templates.SpatialHashGrid: fixed_hashbit-shift that caused collisions for symmetric coordinates;queryRadiusis now O(1) per candidate via a cached bounds map.
Added #
TileMapRenderer.dispose()for releasing the atlasui.Image.
Tests #
- Expanded from 5 to 46 tests.
0.2.0 - 2026-03-15 #
Added #
- Example (
example/example.dart) — full Flutter app demonstrating map parsing, texture atlas construction,TileMapRendererusage, object querying, custom property access, and
0.1.0 - 2026-03-15 #
Added #
-
TileMapParser — async TMX/TSX parser built on the
xmlpackage.TileMapParser.parse(String tmxXml, {TsxProvider?})returns a fully-populatedTiledMap.- Encodings: CSV, Base64, XML (unencoded).
- Compression: None, GZIP, Zlib (via
archive;just_deflatesince 0.4.1), Zstd (viajust_zstd). - Decodes flip bits (horizontal, vertical, diagonal / anti-diagonal) from GIDs and stores them separately.
- Parses embedded and external tileset references; resolves
.tsxfiles via the injectedTsxProvider. - Parses tile animation frame sequences (
<animation>elements). - Parses per-tile collision shapes (polygon / circle objects).
- Typed custom property system:
string,int,float,bool,color,file. - Object template inheritance with per-instance property overrides.
- Tile draw offsets for isometric / staggered alignment.
-
TsxProvider — dependency injection interface for resolving external assets.
DefaultTsxProviderimplementation loads.tsxand template files from the Flutter asset bundle with automatic path normalisation.
-
Data models — immutable value types covering the full Tiled document graph.
TiledMap— root document with computedpixelWidth/pixelHeight,tileLayers,objectGroups,imageLayers, andfindTilesetForGid().- Layer hierarchy — abstract
Layerbase with four concrete types:TileLayer,ObjectGroup,ImageLayer,GroupLayer(nestable). - Common layer properties:
id,name,visible,opacity,offsetX/Y,tintColor,parallelX/Y(parallax factors). Tileset—firstGid, dimensions, spacing, margin,tileOffset, image metadata, per-tile map, andgetSourceRect(localId).Tile—id,type,probability, optional image, collisionobjectGroup,animationframes, custom properties.AnimationFrame—tileId+duration(ms).TiledObject— rectangle, polygon, polyline, ellipse, point, tile object, text object;rotation,gid, template path.TiledProperties— typed accessors:getString(),getInt(),getDouble(),getBool(),has(),operator[].- Enums:
MapOrientation(orthogonal, isometric, staggered, hexagonal),RenderOrder,StaggerAxis,StaggerIndex,DrawOrder,LayerEncoding,LayerCompression.
-
TextureAtlas / TextureAtlasCollection — GPU-optimised tile texture mapping.
TextureAtlaspre-computes sourceRects for every tile in a tileset on construction.TextureAtlasCollection.lookup(gid)resolves the correct atlas and source rect for any GID across multiple tilesets (sorted byfirstGid).
-
TileMapRenderer — hardware-accelerated Canvas renderer.
compile()converts a tile layer toFloat32ListRSTransform + source-rect buffers for a singleCanvas.drawRawAtlascall per layer.render(canvas, cameraOffset, visibleBounds)renders a compiled layer.- Map orientations: Orthogonal, Isometric, Staggered (X/Y axis), Hexagonal — full coordinate transformation for each.
- Tile flipping: Horizontal, Vertical, Diagonal encoded into RSTransform (
scos,ssin,tx,ty). - Layer properties: opacity, tint colour, layer offset, parallax factors.
- Frustum culling: automatic tile-level culling for maps with > 10 000 tiles.
invalidate()marks a renderer for recompilation on the next frame.
-
SpatialHashGrid<T> — generic 2-D spatial index.
insert(),remove(),update()for dynamic objects.query(Rect)AABB query,queryPoint(Offset),queryRadius(Offset, double)circular proximity query.- O(1) average cell hashing via prime multiplication.