This library reads and writes the Tiled TMX format in a simple way. This is useful for map editors or generic level editors, and it’s also useful for using a map editor or generic level editor like Tiled to edit your game’s levels.
To load a TMX file, use tmx.TileMap.load(). You can then read the attributes of the returned tmx.TileMap object, modify the attributes to your liking, and save your changes with tmx.TileMap.save(). That’s it! Simple, isn’t it?
This documentation explains what each attribute means, but if you want to read the TMX spec itself, see this page:
https://github.com/bjorn/tiled/wiki/TMX-Map-Format
This class loads, stores, and saves TMX files.
The TMX format version.
Map orientation. Can be “orthogonal”, “isometric”, or “staggered”.
The width of the map in tiles.
The height of the map in tiles.
The width of a tile.
The height of a tile.
The background color of the map as a hex string (e.g. "FF0000" or "#00FF00"), or None if no background color is defined.
The order in which tiles are rendered. Can be "right-down", "right-up", "left-down", or "left-up". Default is "right-down".
A list of Layer, ObjectGroup, and ImageLayer objects indicating the map’s tile layers, object groups, and image layers, respectively. Those that appear in this list first are rendered first (i.e. furthest in the back).
Load the TMX file with the indicated name and return a TileMap object representing it.
Save the object to the file with the indicated name.
Indicates the format of image data if embedded. Should be an extension like "png", "gif", "jpg", or "bmp". Set to None to not specify the format.
The location of the image file referenced. If set to None, the image data is embedded.
The transparent color of the image as a hex string (e.g. "FF0000" or "#00FF00"), or None if no color is treated as transparent.
The width of the image in pixels; used for tile index correction when the image changes. If set to None, the image width is not explicitly specified.
The height of the image in pixels; used for tile index correction when the image changes. If set to None, the image height is not explicitly specified.
The image data if embedded, or None if an external image is referenced.
The name of the image layer.
The x position of the image layer in pixels.
The y position of the image layer in pixels.
The opacity of the image layer as a value from 0 to 1.
Whether or not the image layer is visible.
The name of the layer.
The opacity of the layer as a value from 0 to 1.
Whether or not the layer is visible.
The global ID of the tile. A value of 0 indicates no tile at this position.
Whether or not the tile is flipped horizontally.
Whether or not the tile is flipped vertically.
Whether or not the tile is flipped diagonally.
The name of the object. An arbitrary string.
The type of the object. An arbitrary string.
The x coordinate of the object in pixels.
The y coordinate of the object in pixels.
The width of the object in pixels.
The height of the object in pixels.
The rotation of the object in degrees clockwise.
The tile to use as the object’s image. Set to None for no reference to a tile.
Whether or not the object is visible.
Whether or not the object should be an ellipse.
A list of coordinate pair tuples relative to the object’s position indicating the points of the object’s representation as a polygon. Set to None to not represent the object as a polygon.
A list of coordinate pair tuples relative to the object’s position indicating the points of the object’s representation as a polyline. Set to None to not represent the object as a polyline.
The name of the object group.
The color used to display the objects in this group as a hex string (e.g. "FF0000" or "#00FF00"). Set to None for no color definition.
The opacity of the object group as a value from 0 to 1.
Whether or not the object group is visible.
A list of Object objects indicating the object group’s objects.
The name of the terrain type.
The local tile ID of the tile that represents the terrain visually.
The local tile ID within its tileset.
Defines the terrain type of each corner of the tile, given as comma-separated indexes in the list of terrain types in the order top-left, top-right, bottom-left, bottom-right. Leaving out a value means that corner has no terrain.
For example, a value of "0,3,,1" indicates that the top-left corner has the first terrain type, the top-right corner has the fourth terrain type, the bottom-left corner has no terrain type, and the bottom-right corner has the second terrain type.
Set to None for no terrain.
A percentage indicating the probability that this tile is chosen when it competes with others while editing with the terrain tool. Set to None to not define this.
The first global tile ID of this tileset (this global ID maps to the first tile in this tileset).
The name of this tileset.
The (maximum) width of the tiles in this tileset.
The (maximum) height of the tiles in this tileset.
The external TSX (Tile Set XML) file to store this tileset in. If set to None, this tileset is stored in the TMX file.
The spacing in pixels between the tiles in this tileset (applies to the tileset image).
The margin around the tiles in this tileset (applies to the tileset image).
The horizontal offset of the tileset in pixels (positive is right).
The vertical offset of the tileset in pixels (positive is down).
A list of TerrainType objects indicating the tileset’s terrain types.
Decode encoded data and return a list of integers it represents.
This is a low-level function used internally by this library; you don’t typically need to use it.
Arguments:
Encode a list of integers and return the encoded data.
This is a low-level function used internally by this library; you don’t typically need to use it.
Arguments: