tile_grid – 2D grid of images

class tile_grid.TileGrid(tiles, map_width, map_height, x=0, y=0, transparent_color=(247, 251, 247), initial_index=0, scale=1)[source]

A grid of image tiles.

This object breaks its display area into a number of bitmap tiles. The user changes the display by changing the tile numbers for each cell in the grid.

Create a new TileGrid.

Parameters
  • tiles (list[Bitmap]) – The tile pictures available in the grid.

  • map_width (int) – The number of tiles across the grid.

  • map_height (int) – The number of tiles down the grid.

  • x (int, optional) – The x coordinate relative to the parent object. Defaults to 0.

  • y (int, optional) – The y coordinate relative to the parent object. Defaults to 0.

  • transparent_color (tuple, optional) – The RGB clear-color value. Defaults to colors.TRANSPARENT.

  • initial_index (int, optional) – The tile to show in each cell on creation. Default is 0.

  • scale (int) – Scale factor for all tiles.

get_tile_index(x=0, y=0)[source]

Return the tile number in the given cell.

Parameters
  • x (int, optional) – The column number of the tile. Defaults to 0 (first column).

  • y (int, optional) – The row number of the tile. Defaults to 0 (first row).

set_tile_image(index, image)[source]

Change the tile image at the given tile index.

Parameters
  • index (int) – The tile index.

  • image (Bitmap) – The new image.

set_tile_index(x=0, y=0, index=0) → None[source]

Set the tile number in the given cell.

Parameters
  • x (int, optional) – The column number of the tile. Defaults to 0 (first column).

  • y (int, optional) – The row number of the tile. Defaults to 0 (first row).

  • index (int, optional) – The tile index number. Defaults to 0 (first image).

Download Source