The tmxlib.layer module

Layer

class tmxlib.layer.Layer(map, name, visible=True, opacity=1)[source]

Base class for map layers

init agruments, which become attributes:

map

The map this layer belongs to. Unlike tilesets, layers are tied to a particular map and cannot be shared.

name

Name of the layer

visible

A boolean setting whether the layer is visible at all. (Actual visibility also depends on opacity)

opacity

Floating-point value for the visibility of the layer. (Actual visibility also depends on visible)

Other attributes:

properties

Dict of properties with string (or unicode) keys and values.

type

'tiles' if this is a tile layer, 'objects' if it’s an object layer, 'image' for an object layer.

index[source]

Index of this layer in the layer list

A Layer is false in a boolean context iff it is empty, that is, if all tiles of a tile layer are false, or if an object layer contains no objects.

Methods:

all_objects()[source]

Yield all objects in this layer

all_tiles()[source]

Yield all tiles in this layer, including empty ones and tile objects

Dict import/export:

to_dict()[source]

Export to a dict compatible with Tiled’s JSON plugin

classmethod from_dict(dct, *args, **kwargs)[source]

Import from a dict compatible with Tiled’s JSON plugin

TileLayer

class tmxlib.layer.TileLayer(map, name, visible=True, opacity=1, data=None)[source]

A tile layer

Acts as a 2D array of MapTile’s, indexed by [x, y] coordinates. Assignment is possible either via numeric values, or by assigning a TilesetTile. In the latter case, if the tileset is not on the map yet, it is added.

See Layer documentation for most init arguments.

Other init agruments, which become attributes:

data

Optional list (or array) containing the values of tiles in the layer, as one long list in row-major order. See TileLikeObject.value for what the numbers will mean.

Methods:

all_objects()

Yield all objects in this layer

all_tiles()[source]

Yield all tiles in this layer, including empty ones.

Tile access:

__getitem__(pos)[source]

Get a MapTile representing the tile at the given position.

Supports negative indices by wrapping in the obvious way.

__setitem__(pos, value)[source]

Set the tile at the given position

The set value can be either an raw integer value, or a TilesetTile. In the latter case, any tileset not in the map yet will be added to it.

Supports negative indices by wrapping in the obvious way.

Methods to be overridden in subclasses:

value_at(pos)[source]

Return the value at the given position

See MapTile for an explanation of the value.

set_value_at(pos, new)[source]

Sets the raw value at the given position

See MapTile for an explanation of the value.

Dict import/export:

to_dict()[source]

Export to a dict compatible with Tiled’s JSON plugin

classmethod from_dict(dct, *args, **kwargs)[source]

Import from a dict compatible with Tiled’s JSON plugin

ObjectLayer

class tmxlib.layer.ObjectLayer(map, name, visible=True, opacity=1, color=None)[source]

A layer of objects.

Acts as a named list of objects. This means semantics similar to layer/tileset lists: indexing by name is possible, where a name references the first object of such name.

See Layer for inherited init arguments.

ObjectLayer-specific init arguments, which become attributes:

color

The intended color of objects in this layer, as a triple of floats (0..1)

Methods:

all_objects()[source]

Yield all objects in this layer (i.e. return self)

all_tiles()[source]

Yield all tile objects in this layer, in order.

Dict import/export:

to_dict()[source]

Export to a dict compatible with Tiled’s JSON plugin

classmethod from_dict(dct, *args, **kwargs)[source]

Import from a dict compatible with Tiled’s JSON plugin

ImageLayer

class tmxlib.layer.ImageLayer(map, name, visible=True, opacity=1, image=None)[source]

An image layer

See Layer documentation for most init arguments.

Other init agruments, which become attributes:

image

The image to use for the layer

Dict import/export:

to_dict()[source]

Export to a dict compatible with Tiled’s JSON plugin

classmethod from_dict(dct, *args, **kwargs)[source]

Import from a dict compatible with Tiled’s JSON plugin

LayerList

class tmxlib.layer.LayerList(map, lst=None)[source]

A list of layers.

Allows indexing by name, and can only contain layers of a single map.

See NamedElementList for LayerList’s methods.

Table Of Contents

Previous topic

The tmxlib.map module

Next topic

The tmxlib.tile module

This Page