TileGrid – A grid of tiles sourced out of one bitmap

Position a grid of tiles sourced from a bitmap and pixel_shader combination. Multiple grids can share bitmaps and pixel shaders.

A single tile grid is also known as a Sprite.

class displayio.TileGrid(bitmap, *, pixel_shader, width=1, height=1, tile_width=None, tile_height=None, default_tile=0, x=0, y=0)

Create a TileGrid object. The bitmap is source for 2d pixels. The pixel_shader is used to convert the value and its location to a display native pixel color. This may be a simple color palette lookup, a gradient, a pattern or a color transformer.

tile_width and tile_height match the height of the bitmap by default.

Parameters:
  • bitmap (displayio.Bitmap) – The bitmap storing one or more tiles.
  • pixel_shader (displayio.Palette) – The pixel shader that produces colors from values
  • width (int) – Width of the grid in tiles.
  • height (int) – Height of the grid in tiles.
  • tile_width (int) – Width of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap’s dimensions.
  • tile_height (int) – Height of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap’s dimensions.
  • default_tile (int) – Default tile index to show.
  • x (int) – Initial x position of the left edge within the parent.
  • y (int) – Initial y position of the top edge within the parent.
hidden

True when the TileGrid is hidden. This may be False even when a part of a hidden Group.

x

X position of the left edge in the parent.

y

Y position of the top edge in the parent.

flip_x

If true, the left edge rendered will be the right edge of the right-most tile.

flip_y

If true, the top edge rendered will be the bottom edge of the bottom-most tile.

transpose_xy

If true, the TileGrid’s axis will be swapped. When combined with mirroring, any 90 degree rotation can be achieved along with the corresponding mirrored version.

pixel_shader

The pixel shader of the tilegrid.

__getitem__(index)

Returns the tile index at the given index. The index can either be an x,y tuple or an int equal to y * width + x.

This allows you to:

print(grid[0])
__setitem__(index, tile_index)

Sets the tile index at the given index. The index can either be an x,y tuple or an int equal to y * width + x.

This allows you to:

grid[0] = 10

or:

grid[0,0] = 10