pyxen.GridMap
A GridMap is a spatial container made of cells arranged in rows and columns.
It defines the tile layout, cell size, optional tile atlas, and the collision space for GridBody.
For collision concepts, see Collision.
Constructor
GridMap(
*,
rows=None,
columns=None,
size=None,
image=None
)
All parameters are keyword-only.
Parameters
| Parameter | Type | Description |
|---|---|---|
rows | int | Number of grid rows |
columns | int | Number of grid columns |
size | (width, height) | Cell size in pixels |
image | str | Tile atlas image name |
Example
level_map = GridMap(
rows=10,
columns=16,
size=(16, 16),
image="tileset"
)
Attaching a GridMap
During spawn:
level = world.spawn(
map=GridMap(
rows=10,
columns=16,
size=(16, 16),
image="tileset"
)
)
Or later:
entity = world.spawn()
entity.map = GridMap(rows=8, columns=8, size=(16, 16))
Properties
map.active
| Property | Type | Default |
|---|---|---|
active | bool | True |
Controls whether collision simulation runs for this map. When False, no body movement, collisions, or callbacks are processed for any GridBody attached to this map.
# Pause collisions (e.g. pause menu)
level.map.active = False
# Resume collisions
level.map.active = True
Modifying Tiles
Use map.set() to configure tiles.
map.set(
row=0,
column=1,
tile=(tile_column, tile_row),
tag=optional_tag
)
Parameters
| Parameter | Type | Description |
|---|---|---|
row | int | Grid row index |
column | int | Grid column index |
tile | (x, y) | Tile coordinates in the atlas |
tag | int | Optional collision tag |
Example: Set a Tile
level.map.set(
row=2,
column=5,
tile=(3, 1)
)
Example: Add Collision Tag
level.map.set(
row=4,
column=2,
tile=(0, 0),
tag=1 # wall
)
Grid Coordinates
- Rows increase vertically
- Columns increase horizontally
Indices outside bounds are safely ignored.
GridMap + GridBody
A GridBody interacts with the GridMap for collision, movement resolution, and trigger detection.
GridBody must be a child of the GridMap entity.
level = world.spawn(
map=GridMap(
rows=8,
columns=8,
size=(16, 16),
image="tiles"
)
)
player = world.spawn(
body=GridBody(),
parent=level
)
Minimal Example: Basic Level
level = world.spawn(
map=GridMap(
rows=8,
columns=8,
size=(16, 16),
image="tiles"
)
)
# Create floor
for r in range(8):
for c in range(8):
level.map.set(row=r, column=c, tile=(0, 0))
# Create walls
for c in range(8):
level.map.set(row=0, column=c, tile=(1, 0), tag=1)
level.map.set(row=7, column=c, tile=(1, 0), tag=1)
Tags
tag is optional metadata per tile.
Typical uses:
0— empty1— wall2— water3— damage zone
Tags are interpreted by your gameplay or collision system.