The tmxlib.tile module

TileLikeObject

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.

Note

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

Tile attributes & methods:
tileset[source]

Get the referenced tileset

value[source]

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.

gid
flipped_horizontally
flipped_vertically
flipped_diagonally

See value

tileset_tile[source]

Get the referenced tileset tile

number[source]

Get the number of the referenced tileset tile

image[source]

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:

hflip()[source]

Flip the tile horizontally

vflip()[source]

Flip the tile vertically

rotate(degrees=90)[source]

Rotate the tile clockwise by the specified number of degrees

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

Inherited:

map
size

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.

MapTile

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:

layer

The associated layer.

pos[source]

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

See TileLikeObject for attributes and methods shered with tile objects.

properties[source]

Properties of the referenced tileset-tile

Note

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