A tile map, tmxlib’s core class
init arguments, which become attributes:
-
size
a (height, width) pair specifying the size of the map, in tiles
-
tile_size
a pair specifying the size of one tile, in pixels
-
orientation
The orientation of the map ('orthogonal', 'isometric',
or 'staggered')
-
background_color
The background color for the map, as a triple of floats (0..1)
Other attributes:
-
tilesets
A TilesetList of tilesets this map uses
-
layers
A LayerList of layers this map uses
-
properties
A dict of properties, with string (or unicode) keys & values
-
pixel_size
The size of the map, in pixels. Not settable directly: use
size and tile_size for that.
-
end_gid
The first GID that is not available for tiles.
This is the end_gid for the map’s last tileset.
Unpacked size attributes:
Each “size” property has corresponding “width” and “height” properties.
-
height
-
width
-
tile_height
-
tile_width
-
pixel_height
-
pixel_width
Methods:
-
add_layer(name, before=None, after=None, layer_class=None)[source]
Add an empty layer with the given name to the map.
By default, the new layer is added at the end of the layer list.
A different position may be specified with either of the before or
after arguments, which may be integer indices or names.
layer_class defaults to TileLayer
-
add_tile_layer(name, before=None, after=None)[source]
Add an empty tile layer with the given name to the map.
See add_layer
-
add_object_layer(name, before=None, after=None)[source]
Add an empty object layer with the given name to the map.
See add_layer
-
add_image_layer(name, image, before=None, after=None)[source]
Add an image layer with the given name and image to the map.
See add_layer
-
all_tiles()[source]
Yield all tiles in the map, including tile objects
-
all_objects()[source]
Yield all objects in the map
-
get_tiles(x, y)[source]
For each tile layer, yield the tile at the given position.
-
check_consistency()[source]
Check that this map is okay.
Most checks are done when reading a map, but if more are required,
call this method after reading.
This will do a more expensive check than what’s practical from within
readers.
Loading and saving (see tmxlib.fileio.ReadWriteBase for more
information):
-
classmethod open(filename, shared=False)
-
classmethod load(string)
-
save(filename)
-
dump(string)
-
to_dict()[source]
Export to a dict compatible with Tiled’s JSON plugin
You can use e.g. a JSON or YAML library to write such a dict to a file.
-
classmethod from_dict(dct, *args, **kwargs)[source]
Import from a dict compatible with Tiled’s JSON plugin
Use e.g. a JSON or YAML library to read such a dict from a file.
Parameters: |
- dct – Dictionary with data
- base_path – Base path of the file, for loading linked resources
|