The tmxlib.mapobject module

MapObject

class tmxlib.mapobject.MapObject(layer, pixel_pos, name=None, type=None)[source]

A map object: something that’s not placed on the fixed grid

Has several subclasses.

Can be either a “tile object”, which has an associated tile much like a map-tile, or a regular (non-tile) object that has a settable size.

init arguments, which become attributes:

layer

The layer this object is on

pixel_pos

The pixel coordinates

pixel_size

Size of this object, as a (width, height) tuple, in pixels.

Only one of pixel_size and size may be specified.

size

Size of this object, as a (width, height) tuple, in units of map tiles.

name

Name of the object. A string (or unicode)

type

Type of the object. A string (or unicode). No semantics attached.

Other attributes:

objtype

Type of the object: 'rectangle', 'tile' or 'ellipse'

properties

Dict of string (or unicode) keys & values for custom data

pos

Position of the object in tile coordinates, as a (x, y) float tuple

map

The map associated with this object

Unpacked position attributes:

x
y
pixel_x
pixel_y

Methods:

to_dict(y=None)[source]

Export to a dict compatible with Tiled’s JSON plugin

classmethod from_dict(dct, layer)[source]

Import from a dict compatible with Tiled’s JSON plugin

RectangleObject

class tmxlib.mapobject.RectangleObject(layer, pixel_pos, size=None, pixel_size=None, name=None, type=None, value=0)[source]

A rectangle object, either blank (sized) or a tile object

See MapObject for inherited members.

Extra init arguments, which become attributes:

pixel_size

Size of this object, as a (width, height) tuple, in pixels. Must be specified for non-tile objects, and must not be specified for tile objects (unless the size matches the tile).

Similar restrictions apply to setting the property (and width & height).

size

Size of this object, as a (width, height) tuple, in units of map tiles.

Shares setting restrictions with pixel_size. Note that the constructor will nly accept one of size or pixel_size, not both at the same time.

value

Value of the tile, if it’s a tile object.

See tmxlib.tile.TileLikeObject for attributes and methods shared with tiles.

EllipseObject

class tmxlib.mapobject.EllipseObject(layer, pixel_pos, size=None, pixel_size=None, name=None, type=None)[source]

An ellipse object

Extra init arguments, which become attributes:

pixel_size

Size of this object, as a (width, height) tuple, in pixels. Must be specified for non-tile objects, and must not be specified for tile objects (unless the size matches the tile).

Similar restrictions apply to setting the property (and width & height).

size

Size of this object, as a (width, height) tuple, in units of map tiles.

Shares setting restrictions with pixel_size. Note that the constructor will nly accept one of size or pixel_size, not both at the same time.

Unpacked size attributes:

width
height
pixel_width
pixel_height

PolygonObject

class tmxlib.mapobject.PolygonObject(layer, pixel_pos, size=None, pixel_size=None, name=None, type=None, points=())[source]

A polygon object

See MapObject for inherited members.

Extra init arguments, which become attributes:

points

Size of this object, as a (width, height) tuple, in pixels. Must be specified for non-tile objects, and must not be specified for tile objects (unless the size matches the tile).

The format is list of iterables: [(x0, y0), (x1, y1), ..., (xn, yn)]

PolylineObject

class tmxlib.mapobject.PolylineObject(layer, pixel_pos, size=None, pixel_size=None, name=None, type=None, points=())[source]

A polygon object

Behaves just like PolygonObject, it’s not closed when drawn. Has the same points attribute/argument as PolygonObject.

Table Of Contents

Previous topic

The tmxlib.tileset module

Next topic

The tmxlib.terrain module

This Page