|

🗺️ RetroPy Map
Module Documentation (MicroPython)
The Map
class provides tilemap loading, rendering, and tile flag integration using .map
files and .rs8
sprite sheets.
📦 Class: Map
🔧 Constructor
Map(map_file, tile_sprite)
map_file
: filename, bytes, or file objecttile_sprite
: a validSprite
object (tileset)
🖼️ Rendering
draw()
: Renders visible area using cameradraw_region(x, y, w, h)
: Draws tile region to screenfill(value)
: Fill entire map with a tileload(path)
: Reload map dataload_sprite(sprite)
: Load a new tileset
🧱 Tile Access
get_tile(x, y)
: Get tile indexset_tile(x, y, index)
: Change tilepixel_to_tile(px, py)
: Convert pixel to tile coordstile_to_pixel(tx, ty)
: Convert tile to pixel coordsin_bounds(x, y)
: Whether coordinates are valid
🧮 Collision & Flags
collide_tiles(Rect)
: Returns list of overlapping tilescollide_flagged(Rect, layer_name)
: Returns overlapping flagged tiles
🏷️ TileFlagLayer Integration
attach(name, layer)
: Attach aTileFlagLayer
get(name)
: Get aTileFlagLayer
by nameget_layer_by_index(i)
: Indexed accesslayer_count
: Returns number of layerslayer_names
: List of names
🔍 Attributes
Attribute | Description |
---|---|
width , height |
Map size in tiles |
tile_size |
Tile size (typically 8 or 16) |
📄 String Representation
print(map)
# Output: <Map WxH tiles, tile_size=S, sprite=WxHxF>
📂 Map File Format
- Byte 0: Magic
0xA1
- Byte 1: Version (0x01+ supports flag layers)
- Bytes 2–3: width
- Bytes 4–5: height
- Byte 6: tile_size
- Byte 8: number of flag layers
- Byte 16+: tile indices (W × H bytes)
- After tile data:
- For each flag layer:
- name_len, name (ASCII), 32-byte bitfield
- For each flag layer: