Loads and renders maps authored in Tiled (.tmj) with chunk streaming
Repository: github.com/dekiengine/deki-tiledmapeditor-integration · Latest release: 0.40.0 · Needs engine 0.40.0+ · Requires: deki-2d, deki-rendering
Install with DekiEditor --packages-add deki-tiledmapeditor-integration <project>, or from the Package Manager. The engine's own components and C++ API are in the Deki docs.
Shown in the editor as Tiled Map Editor Integration.
Components
| Component | Category | Description |
| TilemapColliderComponent | Tilemap | Exposes a tilemap layer's per-tile collision shapes for queries. |
| TilemapComponent | Tilemap | Draws a Tiled map, streaming chunks in around the camera. |
| TilemapObjectSpawner | Tilemap | Spawns objects from a Tiled map's object layers when the scene loads. |
Feature flags
Parts you can leave out of a build. A feature with a define is switched there; the rest are stripped with their components.
| Feature | Define | Default |
| Tilemap Rendering | DEKI_FEATURE_TILEMAP_RENDER | on |
| Tilemap Collision | DEKI_FEATURE_TILEMAP_COLLISION | on |
| Object Layers | DEKI_FEATURE_TILEMAP_OBJECTS | on |
Component reference
TilemapColliderComponent
Exposes a tilemap layer's per-tile collision shapes for queries.
Inspector name: Tilemap Collider Component · Category: Tilemap · Type: DekiTiledMap::TilemapColliderComponent
| Property | Type | Default | Constraints | Description |
| tilemap | AssetRef (Tilemap) | "" | | The map whose tiles become solid. |
| collisionLayer | int32 | 0 | | Which layer of the map holds the collision tiles. A tile present on that layer is solid; an empty cell is not. |
| loopX | bool | false | | Repeat the collision horizontally, to match a map that loops. |
| wrapPeriodX | int32 | 0 | shown when loopX allows | How wide one horizontal repeat is, in tiles. 0 uses the map's own width. |
| loopY | bool | false | | Repeat the collision vertically. |
| wrapPeriodY | int32 | 0 | shown when loopY allows | How tall one vertical repeat is, in tiles. 0 uses the map's own height. |
TilemapComponent
Draws a Tiled map, streaming chunks in around the camera.
Inspector name: Tilemap Component · Category: Tilemap · Type: DekiTiledMap::TilemapComponent
| Property | Type | Default | Constraints | Description |
| tilemap | AssetRef (Tilemap) | "" | | A map exported from Tiled. |
| visibleLayerMask | int32 | 2147483647 | | Which of the map's layers to draw, one bit per layer. All bits set draws everything. |
| chunkPadding | int32 | 1 | | How many chunks beyond the screen edge to keep loaded and drawn. A little padding stops tiles popping in at the edge while scrolling. |
| chunkCacheKiB | int32 | 256 | 16 to 262144 | How much memory this map may keep decoded chunks in, in KiB. Past the budget the least recently drawn chunks are dropped and re-read from storage when they are needed again, so too small shows up as stutter while scrolling rather than as anything missing. 256 suits an ESP32; a desktop can afford far more. |
| tintColor | Color | "#FFFFFFFF" | | Multiplied into every tile. White leaves the map alone. |
| pixelsPerMeter | float | 16 | 1 to 256 | How many of the map's pixels make one meter. This is what lines the map up with everything else in the scene. |
| loopX | bool | false | | Repeat the map horizontally, so scrolling past the edge wraps round. |
| wrapPeriodX | int32 | 0 | shown when loopX allows | How wide one horizontal repeat is, in tiles. 0 uses the map's own width. |
| loopY | bool | false | | Repeat the map vertically. |
| wrapPeriodY | int32 | 0 | shown when loopY allows | How tall one vertical repeat is, in tiles. 0 uses the map's own height. |
Inherits sortingOrder, ignoreClip, pixelSnap, alphaMode from RendererComponent.
TilemapObjectSpawner
Spawns objects from a Tiled map's object layers when the scene loads.
Inspector name: Tilemap Object Spawner · Category: Tilemap · Type: DekiTiledMap::TilemapObjectSpawner
| Property | Type | Default | Constraints | Description |
| tilemap | AssetRef (Tilemap) | "" | | The map whose object layer is read. Each object placed in Tiled becomes an object in the scene. |
| pixelsPerMeter | float | 16 | 1 to 256 | How many of the map's pixels make one meter, so spawned objects land where Tiled put them. |
| sortBase | int32 | 0 | | The Sorting Order of a tile object standing at the world's horizon line (Y 0). |
| sortPerMeter | int32 | 0 | | How much a tile object's Sorting Order rises for each meter lower its point stands. Above 0, what is lower on the screen draws on top, so characters can walk behind things. Set it to the Pixels Per Meter for one order per pixel row, which stacks objects as the Tiled editor does. 0 gives every tile object the Sort Base. |
Changelog
0.40.0
Fixed
- A map under a camera that is not a number, or very far out, draws nothing. Its chunk range wrapped round and Tilemap::QueryVisibleChunks read past the end of its index, which crashed. A range with its ends the wrong way round now returns no chunks.
Changed
- minEngine 0.40.0: built against engine 0.40.0. A build of this package from before does not load and is rebuilt.
- The view copy works with a Pixel Perfect camera on screen pixels. A map drawn at 2x or more is still drawn from its copy when the camera's Pixel Grid is Screen, and scrolls a screen pixel at a time.
Added
- The view copy works on ARGB8888 screens and at 2x, 3x... The copy a map is drawn into once, and copied from while the camera scrolls, was only made for RGB565 screens at 1:1, so a map on an ARGB8888 screen, or drawn larger under Pixel Perfect, was drawn tile by tile every frame. On ARGB8888 it is kept in the screen's format and copied row by row, where the map is the first thing drawn; under Pixel Perfect at a whole scale its tiles land on the same art-pixel grid as on screen. Nothing to set, and the same pixels: frames rendered both ways match. On the Anbernic RG40XX H (640x480, a four-layer isometric farm at 2x) the map went from 13 ms a frame to 2.6. The log says once when a map is drawn from a copy.
- The map's render pass names itself "Tilemap" in the profiler's breakdown by object (RenderPass::Name).
- Isometric maps. Set the map's orientation to Isometric in Tiled and it draws as diamonds, back to front across chunks, with tall tiles standing on their squares. Only chunks in view are loaded. Collision and spawned objects follow the same layout.
- Tile objects placed in Tiled now appear. TilemapObjectSpawner gives each one a sprite of its tile, standing where Tiled draws it, with its flips, size and rotation. Sort Base and Sort Per Meter set its Sorting Order from where its point stands, so what stands lower on the screen can draw on top. A Tile Offset moves the picture without changing the order.
- Tilemap::FindProperty, which finds one of an object's custom properties by name.
- Tilesets with a margin or spacing. These were read as if they had none, which showed the wrong part of the image.
- A tileset's Tile Offset and Object Alignment.
- Group layers. Their layers used to be left out.
- A layer's opacity, tint, offset and parallax, and a group's, drawn as in Tiled. An object layer's opacity, tint and offset apply to its objects.
- Image layers, with their repeat across and down.
- Animated tiles play, in tile layers and as tile objects, on one clock as in Tiled.
- Tile and image layers above an object layer draw above its objects, as Tiled stacks them: the spawner draws them from components of their own.
- Staggered and hexagonal maps, with either stagger axis and index and a hex side length, laid out and drawn in Tiled's order. Collision, spawned objects and Tilemap::PixelsToTile follow the same layout; Tilemap::Stagger() gives the grid.
- A tileset's Tile Render Size set to Map Grid Size, with Fill Mode Stretch or Preserve Aspect Fit: its tiles are drawn at the map's tile size in tile layers.
- Layer blend modes (Add, Multiply, Screen, Overlay, Darken, Lighten, Color Dodge, Color Burn, Hard Light, Soft Light, Difference, Exclusion) on tile and image layers, a group's too, blended as Tiled blends them. A blended layer costs two extra draws and a blend for each of its tiles. An object layer's blend mode is not drawn, and baking says so.
- An object layer's parallax: its spawned objects go in an object named after the layer, which moves with the view before each frame as Tiled moves the layer.
Changed
- A map that scrolls with the camera works out its copy once a frame. A frame redrawn in parts asked the map to draw once for each part, and each time the map found its layers, tilesets, box and copy again; now the frame's first part records what it found and the others only copy their pixels. With 16 sprites moving over the map on a LilyGO T-Deck that was about 15 parts a frame.- Tile layers draw faster, with the same pixels. Each tile gets the runs a sprite gets: its rows' transparent runs are skipped unread and its runs of one colour are filled. Only the cells that can reach the frame (or the strip being drawn) are walked. The tables they need live in external memory, so a board's internal RAM stays for its display and frame. On a LilyGO T-Deck at 320x240, a whole frame of an isometric map went from 34 to 24 ms, a staggered one from 38 to 25 ms and the "Your first game" farm from 38 to 33 ms. A layer with a blend mode draws in about half the time it first did. With the project's redrawChanges on, a map follows a camera that scrolls by whole pixels: only the edge it uncovers is drawn, and the same three maps hold 60 fps (16.6 ms, the display's own rate). That needs the map at the project's pixels per meter, on whole pixels, with parallax 1 and whole layer offsets; any other map redraws the whole frame as before. A layer walks only the cells its own tiles can reach the drawn area from, so a map's tall building tiles no longer widen the walk of its ground (the guide's farm: about 5200 cells walked a frame down to 900), and chunks asked for once in a frame are not asked for again by its later parts.
- A map that scrolls with the camera keeps a copy of its pixels. Each group of layers a map draws together is kept, as drawn, in a buffer a margin larger than the view, in external memory. While the camera moves by whole pixels a frame, or each part redrawn of one, copies the map from there instead of drawing every layer's tiles again, and only what comes into view is drawn, a band at a time, at most one band piece a frame. Where the map is the first thing drawn, the copy holds it over the clear colour and the clear is skipped. The pixels are the ones drawing gives, checked pixel for pixel against drawing on a LilyGO T-Deck over every bench map. On the T-Deck the "Your first game" farm went from 31.7 to about 22.5 ms a frame with the camera following the farmer, and from 53.6 to 34.5 ms with 16 villagers walking. A layer group is drawn as before, every frame, when it has a tint, opacity, blend mode or parallax, animated tiles, tiles with partly see-through pixels, or a map scaled from its pixels per meter, in frames drawn in strips, on a GPU or not in RGB565, with the camera between pixels, and when there is no memory for the copy (about 190 KB at 320x240). A map draws nothing in the parts of a frame away from all its tiles.
- An isometric map used to be drawn as a square grid and now draws correctly. One baked before this keeps the old layout until its .tmj is saved again.
- Object positions and sizes keep Tiled's fractions (DTilemapObject::x, y, width and height are floats). They were rounded down to whole pixels, so an object at 10.5 now lands half a pixel further on. Maps are baked as file version 3; versions 1 and 2 still load, as whole pixels.
- Objects spawned from a Tiled map keep the rotation drawn in Tiled, now that the engine draws positive rotation counter-clockwise (deki-rendering).
- On an isometric map, tiles wider than the grid line up with the left corner of their square, as in Tiled.
- A layer hidden in Tiled is no longer drawn, and collision can still read it. It used to be drawn. Show the layer in Tiled to keep it on screen.
- On a square map, tiles taller than the grid stand on the bottom of their cell, as in Tiled. They used to hang down from its top.
- On a square map, spawned objects land where Tiled shows them: relative to the map's centre, with Y up. They used to be off by the map's size and upside down, so anything placed to make up for that needs moving back.
- A tile object used to spawn as an empty object and now also has a sprite, unless it is hidden in Tiled.
- A tileset baked before this keeps ignoring its margin and spacing until its .tsj is saved again.
- Spawned objects go into an object named "<owner> objects" beside the spawner's object, not under it. Under an object that draws the map they were drawn with it, so a character could never walk behind them. Code that looked for them among the map object's children needs to look there.
- A map baked before this draws without its layers' opacity, tint, offsets, parallax and image layers until its .tmj is saved again (file version 2).
- Sort Per Meter orders are floored, so each step is one order around 0 too, where they used to be cut toward 0 and the two steps either side of 0 shared an order.
0.30.0
Changed
- minEngine 0.30.0: built against engine 0.30.0. A build of this package from before does not load and is rebuilt.
Added
- Tiles carry their tileset image's filter (QuadBlit::Source::filter), so a GPU draws them as its Filter says, each tile within its own texels.
- Tiles carry their atlas's revision (QuadBlit::Source::revision), and each opaque tile copy one of its own, so a GPU drawing the 2D (deki-gl) uploads each tile once. The map pass says it writes nothing into the frame buffer itself (RenderPass::WritesBuffer).
Earlier releases: CHANGELOG.md.
Generated from the package's reflection data (engine 0.40.1). Property names are the keys used in scene files. Renames keep an alias (compatibility).