Skip to content

chunk

FreeBodyEngine.core.tilemap.chunk #

Chunk(tilemap, position, size, data) #

A square block of size x size tiles within a Tilemap layer.

Tile data is stored flat in tiles, a numpy array of _NUM_TILE_VALS values per tile (row-major, see _tile_index), rather than as a grid of Tile objects - Tile instances are only created on demand by get_tile.

Args: tilemap: The Tilemap this chunk belongs to. position: The chunk's position in chunk-grid coordinates (see Tilemap.chunk_pos), not world/tile coordinates. size: The chunk's width/height in tiles. data: Flat per-tile value array backing this chunk, _NUM_TILE_VALS values per tile.

position = position instance-attribute #

size = size instance-attribute #

tilemap = tilemap instance-attribute #

tiles = data instance-attribute #

get_tile(position) #

Builds a Tile view onto the tile at position (local to this chunk).

Tile objects are not stored - this reads the raw values back out of tiles and wraps them fresh on every call.

get_tile_neighbors(position) #

Gets the tile's neighbors, reaching across chunk boundaries as needed.

remove_tile(position) #

Clears the tile at position (local to this chunk) back to empty.

set_tile(position, image_id, spritesheet_index) #

Writes a tile's image id and spritesheet index at position (local to this chunk).