Tilesheets and tilemaps


The Tile class is the base for all tilesheets. It represents a single tile on the map, and contains the tile’s flags, such as whether the tile is solid (ie, can’t be walked through).

class sappho.tilemap.Tile(id_, image, solid_block=False)[source]

A tile object is a sprite, which is typically a subsurface of a tilesheet.


str – The ID of this tile in its respective tilesheet.




bool – If true, this entire tile is completely impassible.


A tilesheet is a collection of tiles, usually loaded from a tilesheet image. A tilesheet image looks like this:


A tilesheet is represented in Sappho by the Tilesheet class. It holds information about the size of the tiles on the tilesheet, a reference to each tile, and of course, the pygame.Surface that holds the tilesheet itself.

class sappho.tilemap.Tilesheet(surface, tiles, tile_size)[source]

Efficient place to update, subsurface tile graphics.




list[Tile] – The tiles composing this Tilesheet.


tuple[int, int] – The size of each tile in pixels (x, y).

classmethod from_file(file_path, tile_width, tile_height)[source]

Creates a tilesheet, and its tiles, from a file, as well as tile width and height specification.

  • file_path (str) – Path to the tilesheet image
  • tile_width (int) – Width of each tile
  • tile_height (int) – Height of each tile
static parse_rules(path_to_rules_file)[source]

Get properties for tile IDs from the path_to_rules_file.

path_to_rules_file (str): Path to the rules file to parse
Returns:A dictionary containing an entry for each tile that has a flag set, the value being a list of the flags that are set
Return type:dict


The TileMap class represents the ordered collection of tiles that make up a game map. Typically, you won’t create a TileMap instance yourself, instead you would load the TileMap from a TMX file using tmx_file_to_tilemaps(), which creates a TileMap for each layer of the TMX map that is passed to it.

tilemap.tmx_file_to_tilemaps(tmx_file_path, tilesheet)

Read TMX file from path and return a list of TileMaps (one TileMap per layer).


Each layer gets its own TileMap!

Return type:



Uses CSV layers; TMX allows all kinds, but CSV is the default.

Once the TileMap has been created, there are a number of methods available on it that are useful, such as getting the solid blocks in the map, and rendering it to a surface.

class sappho.tilemap.TileMap(tilesheet, tiles)[source]

A 2D grid arrangement of tiles, accompanied by passability information.

This is generally one layer of a larger map, and ideally should be blitted to a sappho.layers.SurfaceLayers object to handle multiple map layers.

  • tilesheet (Tilesheet) – Tilesheet to use for this map
  • tiles (list[list[Tile]]) – List of rows, each containing a list of Tile objects representing the tiles in this TileMap

Return the Pygame rect of all the tiles which have the solid_block attribute.

Returns:List of pygame.Rect objects that represent the solid tiles in this TileMap
Return type:list[pygame.Rect]

Blit the TileMap to a surface

Returns:Surface containing the tilemap
Return type:pygame.Surface