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.
- 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.
- 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. equalpyboy.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:
- Returns:
Tile object corresponding to the tile index at the given coordinate in the tile map.
- Return type:
- 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.
- 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 anint.