Tilemap and Sprite Flags

These functions let your Lua code read the map you painted in the Map Editor and inspect the flags you set in the Sprite Editor.

mget

mget(x, y)

Read a tile from the map.

Parameters:
  • x (number) – Tile column in the map grid.

  • y (number) – Tile row in the map grid.

Returns:

Sprite index stored at that map cell.

mget uses tile coordinates, not pixel coordinates. Since each tile is 8 x 8 pixels, divide world positions by 8 and floor the result when converting a pixel position to a map tile.

tile_x = math.floor(player.x / 8)
tile_y = math.floor((player.y + 8) / 8)
tile_sprite = mget(tile_x, tile_y)

fget

fget(spriteIndex, bit)

Read the flags stored on a sprite in the Sprite Editor.

Parameters:
  • spriteIndex (number) – Sprite index in the sprite sheet (0–255).

  • bit (number) – Optional bit index from 0 to 7.

Returns:

The full flag value when bit is omitted, or true/false for a single bit.

Use sprite flags to attach lightweight gameplay metadata to sprites. A common pattern is to mark map tile sprites with flag bits such as “solid” or “hazard”, then check those flags after reading tiles with mget().

tile_sprite = mget(tile_x, tile_y)

if fget(tile_sprite, 0) then
  -- bit 0 is enabled: treat this tile as solid
end

flags = fget(tile_sprite)  -- full 0-255 flag value

Tile collision example

TILE_SIZE = 8
FLAG_SOLID = 0

function is_solid_at_pixel(x, y)
  local tile_x = math.floor(x / TILE_SIZE)
  local tile_y = math.floor(y / TILE_SIZE)
  local sprite_index = mget(tile_x, tile_y)

  return fget(sprite_index, FLAG_SOLID)
end