Base class for a tileset: bank of tiles a map can use.
There are two kinds of tilesets: external and internal. Internal tilesets are specific to a map, and their contents are saved inside the map file. External tilesets are saved to their own file, so they may be shared between several maps. (Of course, any tileset can be shared between maps at the Python level; this distinction only applies to what happens on disk.) External tilesets have the file path in their source attribute; internal ones have source set to None.
tmxlib will try to ensure that each external tileset gets only loaded once, an the resulting Python objects are shared. See ReadWriteBase.open() for more information.
init arguments, which become attributes:
- name¶
Name of the tileset
- tile_size:
A (width, height) pair giving the size of a tile in this tileset. In cases where a tileset can have unequally sized tiles, the tile size is not defined. This means that this property should not be used unless working with a specific subclass that defines tile_size better.
- source¶
For external tilesets, the file name for this tileset. None for internal ones.
Other attributes:
- properties¶
A dict with string (or unicode) keys and values. Note that the official TMX format does not support tileset properties (yet), so editors like Tiled will remove these. (tmxlib saves and loads them just fine, however.)
- terrains¶
A TerrainList of terrains belonging to this tileset. Note that tileset tiles reference these by index, and the indices are currently not updated when the TerrainList is modified. This may change in the future.
- tile_offset¶
An offset in pixels to be applied when drawing a tile from this tileset.
Unpacked versions of tuple attributes:
Loading and saving (see tmxlib.fileio.ReadWriteBase for more information):
List-like access:
Overridable methods:
GID calculation methods:
Note
TilesetList depends on the specific GID calculation algorithm provided by these methods to renumber a map’s tiles when tilesets are moved around. Don’t override these unless your subclass is not used with vanilla TilesetLists.
A tileset whose tiles form a rectangular grid on a single image.
This is the default tileset type in Tiled.
init arguments, which become attributes:
Other attributes:
See Tileset for generic tileset methods.
ImageTileset methods:
A list of tilesets.
Allows indexing by name.
Whenever the list is changed, GIDs of tiles in the associated map are renumbered to match the new set of tilesets.
See NamedElementList for TilesetList’s methods.
Context manager that “wraps” modifications to the tileset list
While this manager is active, the map’s tiles are invalid and should not be touched. After all modification_contexts exit, tiles are renumbered to match the new tileset list. This means that multiple operations on the tileset list can be wrapped in a modification_context for efficiency.
If a used tileset is removed, an exception will be raised whenever the outermost modification_context exits.