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).
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
It holds information about the size of the tiles on the tilesheet,
a reference to each tile, and of course, the
that holds the tilesheet itself.
Tilesheet(surface, tiles, tile_size)¶
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).
from_file(file_path, tile_width, tile_height)¶
Creates a tilesheet, and its tiles, from a file, as well as tile width and height specification.
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
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
tmx_file_to_tilemaps(), which creates a TileMap for each
layer of the TMX map that is passed to it.
Read TMX file from path and return a list of TileMaps (one TileMap per layer).
Each layer gets its own TileMap!
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.
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.SurfaceLayersobject to handle multiple map layers.
Return the Pygame rect of all the tiles which have the solid_block attribute.
Returns: List of
pygame.Rectobjects that represent the solid tiles in this TileMap
Return type: list[pygame.Rect]