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

  1. Project > Create > Tilemap, or Windows > Tilemap > New.
  2. Add tile for each texture you want to paint with (paint them first in Pixel Art).
  3. Paint with the tools:
ToolDoes
Brushpaint the selected tile (or a multi-tile stamp)
Eraserclear cells
Rectfill a rectangle
Fillflood-fill an area
Selectpick a region to copy or move
  1. Use + Layer / − Layer for ground, decoration and overlay layers. Each layer has its own draw order.
  2. Use Resize… to change the grid size, and random rotation / mirror to break up repetition.
  3. 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:B3B79A79FE32ED40

Tiles 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 1
  • size W H is the grid size, and cell 1 is the cell size in world units.
  • tileset N is followed by index textureUUID any|fixed lines. any allows random rotation and mirroring of that tile; fixed keeps it upright.
  • layer Name z visible is followed by H rows of tile indices. . is an empty cell, and the first row is the top of the map.