Skip to content

Layers

This page describes the layer types found in Teeworlds 0.6 maps. Layers define the visual and physical structure of the game world.

Layer Item (type_id = 5)

Every layer item starts with a common header. The remaining fields depend on the layer type.

Common Header

FieldTypeDescription
_versionintUnused (was uninitialized in the editor).
typeintLayer type: 2 = Tilemap, 3 = Quads.
flagsintLayer flags (see below).

Layer Flags

ValueNameDescription
1LAYERFLAG_DETAILLayer should only be rendered on high detail settings.

Tilemap Layer

Tilemap layers contain a grid of tiles. They are the most common layer type and include both visual tiles and the physics-defining Game layer.

sh
// ...common header...
byte[*-...]  // version       - tilemap version (up to 4)
byte[*-...]  // width         - layer width in tiles
byte[*-...]  // height        - layer height in tiles
byte[*-...]  // flags         - tilemap flags (see below)
byte[*-...]  // color_r       - color tint (red, 0-255)
byte[*-...]  // color_g       - color tint (green, 0-255)
byte[*-...]  // color_b       - color tint (blue, 0-255)
byte[*-...]  // color_a       - color tint (alpha, 0-255)
byte[*-...]  // color_env     - color envelope index (-1 if unused)
byte[*-...]  // color_env_offset - color envelope time offset
byte[*-...]  // image         - image index (-1 if unused)
byte[*-...]  // data          - index to the tile data block
byte[*-...]  // name          - (version 3+) I32String name (3 ints)

Tilemap Flags

ValueNameDescription
0TILESLAYERFLAG_NONERegular visual tiles layer.
1TILESLAYERFLAG_GAMEGame layer (defines physics and entities).

Tile Structure

Each tile is 4 bytes in the data block:

ByteNameDescription
0indexTile index (0 = air, 1 = solid, 2 = death, 3 = unhookable, 192+ = entities).
1flagsTile flags (see below).
2skipSkip count for version 4 compression (set to 0 after expansion).
3reservedUnused.

Tile Flags

ValueNameDescription
1TILEFLAG_VFLIPVertical flip.
2TILEFLAG_HFLIPHorizontal flip.
4TILEFLAG_OPAQUEOpaque (for rendering).
8TILEFLAG_ROTATE90° rotation.

The order of operations is: horizontal flip → vertical flip → rotation.

Skip Compression (Version 4)

In version 4 tilemaps, the skip byte is used for compression. Instead of storing a full 2D grid, tiles with the same value are stored once with a skip count indicating how many identical tiles follow.

Example: a tile with skip = 3 means "this tile repeats 3 more times" (4 total identical tiles). After expanding, set skip = 0 on all tiles.

Game Layer

The Game layer is a tilemap layer with TILESLAYERFLAG_GAME set. It defines the physics of the world and the positions of entities.

Physics Tiles

IndexNameDescription
0TILE_AIREmpty space.
1TILE_SOLIDSolid wall (players collide).
2TILE_DEATHDeath tile (kills on contact).
3TILE_NOHOOKSolid but unhookable (hook bounces off).

Entity Tiles

Entity tiles use indices from 192 to 202. Each entity spawns at the center of its tile (pixel position = tile_x * 32 + 16, tile_y * 32 + 16).

IndexNameDescription
192ENTITY_SPAWNDM/TDM spawn point.
193ENTITY_SPAWN_REDRed team spawn point.
194ENTITY_SPAWN_BLUEBlue team spawn point.
195ENTITY_FLAGSTAND_REDRed flag stand (CTF).
196ENTITY_FLAGSTAND_BLUEBlue flag stand (CTF).
197ENTITY_ARMOR_1Armor pickup.
198ENTITY_HEALTH_1Health pickup.
199ENTITY_WEAPON_SHOTGUNShotgun pickup.
200ENTITY_WEAPON_GRENADEGrenade pickup.
201ENTITY_POWERUP_NINJANinja powerup.
202ENTITY_WEAPON_RIFLELaser rifle pickup.

Quads Layer

Quads layers contain textured rectangles. They are used for visual elements like backgrounds and decorations.

sh
// ...common header...
byte[*-...]  // version   - quads version (up to 2)
byte[*-...]  // num_quads - number of quads
byte[*-...]  // data      - index to the quads data block
byte[*-...]  // image     - image index
byte[*-...]  // name      - (version 2+) I32String name (3 ints)

Quad Structure

Each quad is 152 bytes (38 ints) in the data block:

FieldIntsTypeDescription
positions10Point[5]5 corner positions (22.10 fixed-point).
corner_colors16Color[4]4 corner colors (r, g, b, a).
texture_coords8Point[4]4 texture coordinates (0-1024 range).
pos_env1intPosition envelope index (-1 if unused).
pos_env_offset1intPosition envelope time offset.
color_env1intColor envelope index (-1 if unused).
color_env_offset1intColor envelope time offset.

INFO

Corner order: top-left → top-right → bottom-left → bottom-right. The 5th point in positions is the pivot. Divide positions by 512 to get world coordinates. Divide texture coordinates by 1024 to normalize to (0, 1) range.