The tmxlib.tile module


class tmxlib.tile.TileLikeObject[source]

Bases: tmxlib.helpers.TileMixin

Base tile-like object: regular tile or tile object.

Has an associated layer and value, and can be flipped, etc.

A TileLikeObject is “true” iff there’s a tile associated with it. Empty, “false” tiles have a GID of zero.


Subclasses should use the _value attribute for your own purposes. The value allows setting itself to TilesetTiles, has checks, etc.

Tile attributes & methods:

Get the referenced tileset


Numeric value of a tile, representing the image and transformations.

See the TMX format for a hopefully more detailed specification. The upper bits of this number are used for flags:

  • 0x80000000: tile is flipped horizontally.
  • 0x40000000: tile is flipped vertically.
  • 0x20000000: tile is flipped diagonally (axes are swapped).
  • 0x10000000: tmxlib reserves this bit for now, just because 0x0FFFFFFF is a nice round number.

The rest of the value is zero if the layer is empty at the corresponding spot (or an object has no associated tile image), or it holds the GID of the tileset-tile.

The GID can be computed as 1 + X + Y where X is the number of tiles in all tilesets preceding the tile’s, and Y is the number of the tile within its tileset.

The individual parts of value are reflected in individual properties:

  • flipped_horizontally (0x80000000)
  • flipped_vertically (0x40000000)
  • flipped_diagonally (0x20000000)
  • gid (0x0FFFFFFF)

The properties themselves have a value attribute, e.g. tmxlib.MapTile.flipped_diagonally.value == 0x20000000.


See value


Get the referenced tileset tile


Get the number of the referenced tileset tile


Get the image of the tile. (N.B. see full docstring!)

N.B. No transformations are applied to the image. This can change in future versions. Use self.tileset_tile.image for future-safe behavior.

get_pixel(x, y)[source]

Get the pixel at the given x, y coordinates.

Handles negative indices in the obvious way.

tile_to_image_coordinates(x, y)[source]

Transform map-tile pixel coordinates to tileset-tile pixel coords.

Handles negative indices in the obvious way.

Flipping helpers:


Flip the tile horizontally


Flip the tile vertically


Rotate the tile clockwise by the specified number of degrees

Note that tiles can only be rotated in 90-degree increments.



Size of the referenced tile, taking rotation into account. The size is given in map tiles, i.e. “normal” tiles are 1x1. A “large tree” tile, twice a big as a regular tile, would have a size of (1, 2). The size will be given as floats.

Empty tiles have (0, 0) size.


class tmxlib.tile.MapTile(layer, pos)[source]

References a particular spot on a tile layer

MapTile object can be hashed and they compare equal if they refer to the same tile of the same layer.

init arguments, which become attributes:


The associated layer.


The associated coordinates, as (x, y), in tile coordinates.

See TileLikeObject for attributes and methods shered with tile objects.


Properties of the referenced tileset-tile


Changing this will change properties of all tiles using this image. Possibly even across more maps if tilesets are shared.

See TilesetTile.

Table Of Contents

Previous topic

The tmxlib.layer module

Next topic

The tmxlib.tileset module

This Page