Skip to content

LDtk Auto-Layer Rules from an Autotile Sheet

LDtk auto-layer rules are powerful but "prep-heavy". The Studio writes one rule per tile from the recognised terrain bits — checked against LDtk's JSON schema, its official loader and an independent re-run of the rules, but not opened in the LDtk editor.

In LDtk, autotiling is an IntGrid layer with a tileset and auto-layer rules: each rule is a pattern of IntGrid values (1 × 1 up to 7 × 7) that paints a tile where it matches; rules run from the top and "break on match" stops later rules in that cell. Nerulio turns every tile of an autotile sheet into one 3 × 3 rule — 47 for a blob set — and writes an LDtk 1.5.3 project with a sample level. The file passes LDtk's JSON schema and official loader and re-running the rules reproduces its tiles, but it was not opened in the LDtk app.

Drop a tileset or autotile sheet (PNG)
Runs in your browser. Files are not uploaded.
Studio Tile workspace: a 47-tile sheet recognised as the GameMaker layout, with its terrain bits and a complete check
The real Studio with a CC0 asset (OpenGameArt).
Exports to
  • LDtkPartly verified· LDtk 1.5.3 schema + loader
  • Godot 4 TileSetVerified· Godot 4.7.2
  • TiledVerified· Tiled 1.12.2
  • Unity 6 Rule TileVerified· Unity 6000.5.3f1 + 2D Tilemap Extras 8.0.3

IntGrid values, rules and their order

The LDtk manual describes auto-layers as "IntGrid layers with a twist": a tileset linked to them and rules that paint tiles automatically. You paint integer values (the JSON reference: 0 is an empty cell, values start at 1), and the rules turn them into tiles; a pure auto-layer can instead read its values from another IntGrid layer.

A rule is a square pattern over the cell and its neighbours plus the tile it paints. In the file Nerulio writes, a pattern cell holds v (the neighbour must be value v), −v (it must not be v) or 0 (anything), row by row from the top-left, and the tile lands on the centre cell. Corners behind an open side are 0, so a blob rule checks between 5 and 9 cells. The JSON reference defines breakOnMatch ("prevent other rules to be applied in the same cell if it matches"), so Nerulio sorts the rules most specific first and keeps it on.

Corner (dual-grid) sets use LDtk's tile offset: each rule reads the cell, its right, bottom and bottom-right neighbours — the four cells that meet at one grid point — and draws its tile half a tile down and right, on that point.

IntGrid value
An integer painted per cell; each terrain gets one (terrain 1 = value 1, and so on).
Auto-layer rule
A pattern of required and forbidden values plus the tile to paint where it matches.
Break on match
When a rule matches, later rules skip that cell (LDtk's default).
Tile offset
A per-rule pixel shift of the painted tile; half a tile for dual-grid sets.

Example: the 3 × 3 rule for one blob tile (terrain = IntGrid value 1)

tile mask 31: N, NE, E, SE, S connected, W open
pattern, row by row from the top-left:
   0   1   1        1 = must be value 1
  -1   1   1       -1 = must not be value 1
   0   1   1        0 = anything (corners behind the open west side)
JSON  "size":3, "pattern":[0,1,1,-1,1,1,0,1,1], "breakOnMatch":true
rules  blob-47 → 47,  16-side → 16,  16-corner → 15 (the all-empty corner tile draws nothing)

Cells outside the level count as empty (outOfBoundsValue 0), so terrain touching the level border gets its rim tiles.

What it does

  • .ldtk (1.5.3) with an IntGrid value per terrain and one 3×3 rule per tile.
  • A sample level with autoLayerTiles already filled, so the result can be inspected.
  • Corner / dual-grid sets written with a half-tile tile offset.
  • PARTLY VERIFIED: schema + official QuickType loader + independent rule re-run equal to the exported tiles on 12 corpus sets.

How to do it

  1. Drop the tileset and apply its layout (or paint the bits).
  2. Read the Check panel and fill missing combinations.
  3. Export (Ctrl+E) and take the ldtk folder.
  4. Open the .ldtk in LDtk and paint the IntGrid layer.

Files you get

The ldtk folder of the export ZIP, for a sheet called cave.png:

FileWhat it is for
cave.ldtkAn LDtk 1.5.3 project: tileset definition, IntGrid layer Terrain with one value per terrain, rule group Nerulio terrain, and a level Sample whose autoLayerTiles are already filled.
cave.pngThe tileset image, referenced by its file name.
README.txtWhat the project contains and how many tiles the sample level places.

Open and paint it in LDtk

  1. Unzip the ldtk folder and keep the PNG next to the .ldtk file.
  2. Open the .ldtk in LDtk. The level Sample already shows the tiles the rules place.
  3. In the LAYERS panel select the IntGrid layer Terrain: its values are your terrains and its AUTO PAINT tileset is your PNG.
  4. Click the RULES button of the layer to see the group Nerulio terrain with one rule per tile, in the order they are tested.
  5. Paint values with the left mouse button, erase with the right, Shift + drag for rectangles and Shift + click to fill; LDtk re-runs the rules as you paint. Shift+R in the Rules panel shows the raw IntGrid.
  6. In your game, read the level's autoLayerTiles (LDtk stores them already in display order) or intGridCsv if you run your own rules.

Check the result

  • The Sample level shows complete terrain before you paint anything.
  • The rule group lists 47 rules for a blob set (16 for a side set, 15 for a corner set).
  • Paint a single cell and a 3 × 3 square: the isolated tile and 9 different tiles appear. We have not seen this inside the LDtk app — it is the check we could not run, so please report a difference.

Troubleshooting

SymptomLikely causeHow to checkFix
The tileset image is missingThe PNG is not next to the .ldtk or was renamedTileset definition: path of the imagePut the PNG beside the project under its exported name
Painting shows values but no tilesPainting on another layer, or the layer's rules are switched offLAYERS panel selection; Render option in the Rules panelSelect Terrain and keep the rule group active
A generic tile shows where a specific one belongsA rule of your own sits above the group, or Break on match was switched offRule order in the Rules panelMove your rule below the group, or turn Break on match back on
Dual-grid tiles look half a tile off the IntGridBy design: corner rules paint on grid points with a half-tile offsetTile offset of any rule in the groupKeep it; the tiles line up with each other, not with the IntGrid cells
No ldtk folder in the ZIPLDtk needs square tiles and one padding and spacing valueNOTES.txt says why it was skippedUse a square grid with equal x and y margin and spacing
Two terrains meet without a transitionThe sheet has no tiles that show both terrainsStudio Check panel for that pairGenerate A-over-B tiles in the generator

Other ways to do it

OptionWhen it is the better choice
Write the rules by hand in LDtk's rule editorFewer tiles with LDtk features the export does not use: flipped patterns, modulo, checker, random chance, several tiles per rule.
A Tiled Wang set: Tiled Wang setYou edit maps in Tiled and want a terrain brush instead of IntGrid painting.
Godot terrains: Godot 4 autotileGodot is your engine and you do not need LDtk's level editor.

Engine exports and how each was checked

"Verified" means the exported files were loaded by the real engine or tool on real CC0 assets and the result was compared with the source. Anything that was not loaded is labelled as such.

TargetFilesCheck
Godot 4 TileSetPNG · nerulio-tileset.json · nerulio_tileset_import.gdVerified Godot 4.7.2The included import script builds the TileSet with terrain peering bits; a map painted with set_cells_terrain_connect equals the Studio preview in every cell on 9 corpus sheets.
Tiled.tsx Wang set · sample.tmxVerified Tiled 1.12.2Tiled's own readers load every Wang ID as written and the sample map renders pixel-exact. The terrain brush itself was not driven.
Unity 6 Rule Tilenerulio-ruletile.json · Editor/NerulioRuleTileImporter.csVerified Unity 6000.5.3f1 + 2D Tilemap Extras 8.0.3Blob and side sets: a painted Tilemap shows the predicted sprite in every cell. Corner / dual-grid sets are not exported to Unity.
LDtk.ldtk (1.5.3) · rules · sample levelPartly verified LDtk 1.5.3 schema + loaderAccepted by the LDtk JSON schema and its official loader, and the rules re-run to the exported tiles; not opened in the LDtk app.

Evidence

Layouts identified from the pixels alone on the tile corpus: 4 blob-47 templates and 2 Wang templates with high confidence, a real 64 px cave tileset with medium confidence — every tile's bits right. Godot 4.7.2 painted every test cell exactly as the Studio predicted (485/485 per blob set, 251/251 on a 4-terrain dual-grid pack); Tiled 1.12.2 read every Wang ID back; Unity 6000.5 matched on every painted cell of the blob and side sets.

Limits

  • Not opened in the LDtk app (it has no command line); the checks were the schema, the official loader and an independent re-run of the rules.
  • One rule per tile: flips, modulo, checker and Perlin options are left off.
  • Tiles must be square, with the same margin and spacing on both axes.
  • Tiled's terrain brush, the LDtk app and Godot's editor painter were not driven; the checks use the engines' readers and set_cells_terrain_connect.
  • Unity gets blob and side sets only; several terrains become several Rule Tiles with no transitions between them.
  • Isometric and hex tiles, animated tiles, occlusion and navigation layers are out of scope.
  • Suggesting bits without a known layout needs a reference "full" tile; on side-only path templates the guess can fail until you select it.

Versions and sources

Checked on 12 corpus sets: the project passed the LDtk 1.5.3 JSON schema and loaded with LDtk's official QuickType loader, and an independent re-run of the rules gave exactly the exported tiles. A changed tile id or an inverted rule makes the check fail. UI names above come from the LDtk documentation; the app itself was not driven.

Official documentation used

Questions

Why only "partly verified"?

LDtk ships as an Electron app with no command line, so it was not opened in the app. The file passed LDtk's JSON schema and its official loader, and re-running the rules gave the exported tiles.

Can one sheet hold several terrains?

Yes: each terrain gets its own IntGrid value and its own rules.

Is it free, and do I need an account?

Everything on these pages is free and works without an account. There is no watermark and no export that is held back.

Are my sprites uploaded?

No. The Studio decodes, packs and exports in this browser tab. Projects are autosaved in the browser (IndexedDB) and can be saved as a .nerulio file.

Does it need Aseprite or an engine plugin installed?

No. .aseprite files are read and written in the browser, and each engine bundle carries what that engine needs (for Godot, the import settings and scene; for Unity and the Godot TileSet, a small editor script).