coloX Map API
The coloX map system assembles images from sprite tiles, supporting fast drawing of large regions and textured line effects.
Contents
1. Map Data
Maps consist of 8×8-pixel sprite tiles. Each map element is a 16-bit integer (usually a sprite index). Tile number 0 is not drawn by default.
mget(x, y) → value
Gets data at map coordinates (x, y). Returns 0 when out of bounds or when the tile number exceeds the sprite sheet range.
mset(x, y, val)
Sets data at map coordinates (x, y).
-- Read a map element
local tile = mget(5, 3)
-- Modify the map at runtime
mset(5, 3, 42)
2. Map Drawing
map(tile_x, tile_y [, sx, sy [, tile_w, tile_h [, layers]]])
Draws a map region to the screen.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
tile_x, tile_y | number | 0, 0 | Starting map coordinates (in tiles) |
sx, sy | number | 0, 0 | Destination screen position (pixels) |
tile_w, tile_h | number | Maximum width/height | Number of tiles to draw (explicit nil does not use the default; it is treated as 0, so nothing is drawn) |
layers | number | None | Layer filter mask (bitfield) |
-- Draw a 4×2 map region at screen position (20, 20)
map(0, 0, 20, 20, 4, 2)
-- Combine with camera to move the map with the character
camera(player.x - __vm_width / 2, player.y - __vm_height / 2)
map() -- Draw the entire map
camera() -- Reset
layers parameter: When supplied, only tiles whose sprite flags have the corresponding bits set to 1 are drawn.
-- Draw only tiles with bit0 or bit2 set (16×16 tiles)
map(0, 0, 0, 0, 16, 16, 0x05) -- 0x05 = bit0 | bit2
-- Layered drawing: background first, then foreground
map(0, 0, 0, 0, 16, 16, 0x01) -- bit0 = background
map(0, 0, 0, 0, 16, 16, 0x02) -- bit1 = foreground
Map width can be changed dynamically using
statctl('mapw', w)(0 restores the specification's default width), affecting coordinate conversion inmap/mget/mset.
3. Textured Lines
tline(x0, y0, x1, y1, mx, my [, mdx, mdy])
Draws a textured line from (x0,y0) to (x1,y1), sampling the texture from the map.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
x0, y0 | number | Required | Starting coordinates |
x1, y1 | number | Required | Ending coordinates |
mx, my | number | Required | Starting map sampling position (in tiles; fractions supported) |
mdx, mdy | number | 1/8, 0 | Map coordinate increment per pixel |
Map coordinates:
2.0, 1.0— start at the upper-left corner of the tile at map position (2, 1)2.5, 1.5— start at the middle (4, 4) of the tile
-- Basic textured line
tline(0, 100, 240, 100, 0, 0)
-- Scaled textured line (mdx=0.25 advances one tile per 4 pixels)
tline(0, 100, 240, 100, 0, 0, 0.25, 0)
Texture wrapping controls (through statctl):
-- Repeat 8 tiles horizontally and 4 tiles vertically
statctl('tlmw', 8)
statctl('tlmh', 4)
tline(...)
-- Set the sampling offset
statctl('tlmx', offset_x)
statctl('tlmy', offset_y)
-- Default (0, 0): repeat over 256 tiles
Sprite number 0 is not sampled or drawn (as with
map).
4. Complete API Index
| Function | Description |
|---|---|
mget(x, y) | Get map data |
mset(x, y, val) | Set map data |
map(tile_x, tile_y [, sx, sy [, tw, th [, layers]]]) | Draw a map region |
tline(x0, y0, x1, y1, mx, my [, mdx, mdy]) | Draw a textured line |
Related statctl Keys
| Key | Description |
|---|---|
tlmw | tline map width mask |
tlmh | tline map height mask |
tlmx | tline map X offset |
tlmy | tline map Y offset |