The tmxlib.map module

Map

class tmxlib.map.Map(size, tile_size, orientation='orthogonal', background_color=None, base_path=None, render_order=None, stagger_index=None, hex_side_length=None, stagger_axis=None)[source]

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)

stagger_axis

Stagger axis for hexagonal maps (‘x’ or ‘y’, or None)

stagger_index

Stagger index for hexagonal maps (‘odd’ or ‘even’, or None)

hex_side_length

Side length for hexagonal maps (int, or None)

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.

Table Of Contents

Previous topic

tmxlib Module Reference

Next topic

The tmxlib.layer module

This Page