Tile map

Technical overview. The background and window each use a 32 by 32 map of tile identifiers stored in video RAM. The LCD controller selects the map and the tile-data addressing mode, so an identifier can refer to different pixel data depending on the current hardware configuration.

Using the API. TileMap is exposed through pyboy.tilemap_background and pyboy.tilemap_window. Index it with coordinates or slices to read identifiers, search for identifiers across the map, or enable tile objects when the corresponding Tile data is needed.

The Game Boy has two tile maps, which defines what is rendered on the screen.

class pyboy.api.tilemap.TileMap(pyboy, mb, select)[source]

Bases: object

shape

Tile maps are always 32x32 tiles.

Returns:

The width and height of the tile map.

Return type:

(int, int)

search_for_identifiers(identifiers)[source]

Provided a list of tile identifiers, this function will find all occurrences of these in the tilemap and return the coordinates where each identifier is found.

Example:

>>> pyboy.tilemap_window.search_for_identifiers([5,3])
[[[9, 11]], [[9, 9], [9, 12]]]

Results are grouped in the same order as identifiers. Each match is a [row, column] pair.

Parameters:

identifiers (iterable[int]) – Tile identifiers to search for.

Returns:

Matches grouped by input identifier; each match is a [row, column] pair.

Return type:

list[list[list[int]]]

tile(column, row)[source]

Provides a pyboy.api.tile.Tile-object which allows for easy interpretation of the tile data. The object is agnostic to where it was found in the tilemap. I.e. equal pyboy.api.tile.Tile-objects might be returned from two different coordinates in the tile map if they are shown different places on the screen.

Parameters:
  • column (int) – Column in this tile map.

  • row (int) – Row in this tile map.

Returns:

Tile object corresponding to the tile index at the given coordinate in the tile map.

Return type:

pyboy.api.tile.Tile

tile_identifier(column, row)[source]

Returns an identifier (integer) of the tile at the given coordinate in the tile map. The identifier can be used to quickly recognize what is on the screen through this tile view.

This identifier unifies the otherwise complicated indexing system on the Game Boy into a single range of 0-383 (both included).

You can read how the indexes work in the Pan Docs: VRAM Tile Data.

Parameters:
  • column (int) – Column in this tile map.

  • row (int) – Row in this tile map.

Returns:

Tile identifier.

Return type:

int

use_tile_objects(switch)[source]

Used to change which object is returned when using the __getitem__ <pyboy.api.tilemap.TileMap>` method (i.e. `` tilemap[0,0]`).

Parameters:

switch (bool) – If True, accesses will return pyboy.api.tile.Tile-object. If False, accesses will return an int.