Building 2D games
Tilemaps
Painting grid-based levels with the Tilemap window and placing them in a 2D scene.
A tilemap is a grid of tiles, where each tile is a texture. It is stored in one
.tgtilemap file and drawn by a single entity.
Making one
- Project > Create > Tilemap, or Windows > Tilemap > New.
- Add tile for each texture you want to paint with (paint them first in Pixel Art).
- Paint with the tools:
| Tool | Does |
|---|---|
| Brush | paint the selected tile (or a multi-tile stamp) |
| Eraser | clear cells |
| Rect | fill a rectangle |
| Fill | flood-fill an area |
| Select | pick a region to copy or move |
- Use + Layer / − Layer for ground, decoration and overlay layers. Each layer has its own draw order.
- Use Resize… to change the grid size, and random rotation / mirror to break up repetition.
- Save.
Putting it in a scene
Drag the .tgtilemap from the Project panel into the Hierarchy (empty area) or the Scene
view. Or select an entity with a 2D position and use Add Component > Tilemap. The entity's
position is the map's bottom-left corner, and each cell is one world unit.
tgscene
-DemoMap:
-Position2D:0,0
-Tilemap:B3B79A79FE32ED40Tiles from a map show greyed out in the Hierarchy. Edit them in the Tilemap window, not one by one.
The file format
.tgtilemap is plain text, so it's easy to generate with a script or an AI:
tilemap 1
size 10 6
cell 1
tileset 2
0 7F4A09AFD320074C any
1 F773BD1015D0DE41 fixed
layer Ground 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
layer Decor 50 1
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
1 1 1 1 1 1 1 1 1 1size W His the grid size, andcell 1is the cell size in world units.tileset Nis followed byindex textureUUID any|fixedlines.anyallows random rotation and mirroring of that tile;fixedkeeps it upright.layer Name z visibleis followed byHrows of tile indices..is an empty cell, and the first row is the top of the map.