How to Build a 2D Tilemap Level with Auto-Tiling and Collision
Design 2D game levels from tiles: layers, auto-tiling with 4-bit and blob bitmasks, collision flags, object layers and Tiled JSON export for your engine.

How to Build a 2D Tilemap Level with Auto-Tiling and Collision
Most 2D games, from top-down adventures to platformers, draw their worlds from a grid of small square images called tiles. Instead of painting one huge picture, you build a level from a few hundred reusable pieces, which keeps memory use low and makes changes cheap. This guide explains how tilemaps work and walks through a small level in the free tilemap and level editor, which runs in the browser and keeps your maps on your own device.
Tiles, tilesets and the grid
A tileset is one image cut into equal squares. The editor ships with a built-in 16 px set that includes water and wall terrains, plain fills and props such as crates and plants. You can also load your own PNG and tell the editor the tile size, for example 32 × 32 px. Each square gets an index, and the map itself is just a grid of those numbers. A 40 × 25 map is 1,000 cells, and each cell stores one tile index per layer.
Layers keep the level manageable
Real levels are drawn in layers. A typical setup has a ground layer (grass, floor), a decoration layer on top (flowers, cracks) and an object layer for things that are not tiles at all. Each layer has its own visibility, opacity and order, so you can hide the decoration while you fix the floor, or dim the ground to see objects clearly.
Object layers hold rectangles with a name and a type such as spawn, enemy, trigger or collision. Your game code reads them to know where the player starts, where a door opens or which area starts a cut-scene.
Drawing tools
- Stamp places the selected tile. Drag across several tiles in the palette to pick a block, such as a 2 × 3 tree, and stamp it in one click.
- Erase clears cells; right-dragging erases too, so you rarely need to switch tools.
- Rectangle fills an area, and flood fill replaces a connected region of the same tile.
- Picker grabs the tile under the cursor, which is faster than searching the palette.
Undo and redo cover every stroke, and the map can be resized later if the level grows.
How auto-tiling works
Drawing a lake by hand means choosing the right corner and edge piece for every border cell. Auto-tiling does that for you. The terrain brush looks at the neighbours of each cell and picks the matching tile.
The simplest scheme is a 16-tile set with a 4-bit bitmask. Each direction has a value: north = 1, east = 2, south = 4, west = 8. Add the values of the neighbours that contain the same terrain. A water cell with water to the north and east but not south or west scores 1 + 2 = 3, so the brush uses tile 3, which shows shore on the south and west sides. A cell surrounded on all four sides scores 15, the full water tile. A lone puddle scores 0.
The 4-bit scheme ignores diagonals, so inner corners can look blocky. The 47-tile "blob" scheme uses an 8-bit mask that also counts the four diagonals, but only when both adjacent edges are present. That rule collapses the 256 possible combinations to 47 distinct tiles and gives smooth inner and outer corners.
Collision
Each tile in the set can carry a "collides" flag and a type property, for example wall or water. Turn on the collision overlay and every blocking cell is tinted, which makes gaps in a wall easy to spot before you test in the game.
A worked example
Suppose you make a 30 × 20 map at 16 px, which gives a 480 × 320 px level. You paint grass with the rectangle tool, then use the water terrain brush to draw an L-shaped pond of about 40 cells; the brush picks every shore tile. You mark water and wall tiles as colliding, add a spawn object at cell (3, 10) and an enemy rectangle near the pond. The collision overlay shows one gap in the north wall, which you close with two stamp clicks.
Exporting to your engine
The main export is Tiled JSON (.tmj, format 1.10) with the tileset embedded, including the collides properties. It opens in the Tiled editor, and engines such as Godot, Phaser and Unity can load it through their Tiled importers. You also get the tileset PNG, a PNG of the whole map, each layer as CSV and a collision grid as JSON, which is handy if you write your own loader. The editor can import Tiled JSON maps whose layers use CSV encoding.
Limits
The editor supports orthogonal maps only, not isometric or hexagonal ones. Each map uses one tileset, and animated tiles are not supported. Tiled files that store layers as base64 or compressed data will not import; save them with CSV encoding first. Maps and custom tilesets live in browser storage, which is limited to roughly 5 MB, so export your work regularly.



