Objects#
This module provides classes for all of the Tiled Object types.
There is the base TiledObject class, which all of the actual object types inherit from. The base TiledObject class is never directly used, and serves only as an abstract base for common elements between all types.
Some objects have no extra attributes over the base class, they exist as different classes anyways to denote the type of object, so that an implementation can load it in accordingly. For example, an Ellipse and a Point have no differing attributes from the base class, but obviously need to be handled very differently.
For more information about objects, see Tiled’s Manual
Also see the TMX Reference and JSON Reference
TiledObject#
- class pytiled_parser.tiled_object.TiledObject(*, id: int, coordinates: OrderedPair, size: Size = Size(width=0, height=0), rotation: float = 0, visible: bool = True, name: str = '', class_: str = '', properties: Dict[str, Union[float, Path, str, bool, Color]] = {})#
TiledObject object.
- id_#
Unique ID of the tiled object. Each tiled object that is placed on a map gets a unique id. Even if an tiled object was deleted, no tiled object gets the same ID.
- gid#
Global tiled object ID.
- coordinates#
The location of the tiled object in pixels.
- size#
The width of the tiled object in pixels (default: (0, 0)).
- rotation#
The rotation of the tiled object in degrees clockwise (default: 0).
- Type:
float
- opacity#
The opacity of the tiled object. (default: 1)
- name#
The name of the tiled object.
- Type:
str
- class_#
The Tiled class of the tiled object.
- Type:
str
- properties#
The properties of the TiledObject.
- Type:
Dict[str, Union[float, pathlib.Path, str, bool, pytiled_parser.common_types.Color]]
Ellipse#
- class pytiled_parser.tiled_object.Ellipse(*, id: int, coordinates: OrderedPair, size: Size = Size(width=0, height=0), rotation: float = 0, visible: bool = True, name: str = '', class_: str = '', properties: Dict[str, Union[float, Path, str, bool, Color]] = {})#
Elipse shape defined by a point, width, height, and rotation.
See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#ellipse
Point#
- class pytiled_parser.tiled_object.Point(*, id: int, coordinates: OrderedPair, size: Size = Size(width=0, height=0), rotation: float = 0, visible: bool = True, name: str = '', class_: str = '', properties: Dict[str, Union[float, Path, str, bool, Color]] = {})#
Point defined by a coordinate (x,y).
See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#point
Polygon#
- class pytiled_parser.tiled_object.Polygon(*, id: int, coordinates: OrderedPair, size: Size = Size(width=0, height=0), rotation: float = 0, visible: bool = True, name: str = '', class_: str = '', properties: Dict[str, Union[float, Path, str, bool, Color]] = {}, points: List[OrderedPair])#
Polygon shape defined by a set of connections between points.
See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#polygon
- points#
List of coordinates relative to the location of the object.
- Type:
Polyline#
- class pytiled_parser.tiled_object.Polyline(*, id: int, coordinates: OrderedPair, size: Size = Size(width=0, height=0), rotation: float = 0, visible: bool = True, name: str = '', class_: str = '', properties: Dict[str, Union[float, Path, str, bool, Color]] = {}, points: List[OrderedPair])#
Polyline defined by a set of connections between points.
- points#
List of coordinates relative to the location of the object.
- Type:
Rectangle#
- class pytiled_parser.tiled_object.Rectangle(*, id: int, coordinates: OrderedPair, size: Size = Size(width=0, height=0), rotation: float = 0, visible: bool = True, name: str = '', class_: str = '', properties: Dict[str, Union[float, Path, str, bool, Color]] = {})#
Rectangle shape defined by a point, width, and height.
- See: https://doc.mapeditor.org/en/stable/manual/objects/#insert-rectangle
(objects in tiled are rectangles by default, so there is no specific documentation on the tmx-map-format page for it.)
Text#
- class pytiled_parser.tiled_object.Text(*, id: int, coordinates: OrderedPair, size: Size = Size(width=0, height=0), rotation: float = 0, visible: bool = True, name: str = '', class_: str = '', properties: Dict[str, Union[float, Path, str, bool, Color]] = {}, text: str, color: Color = Color(red=255, green=255, blue=255, alpha=255), font_family: str = 'sans-serif', font_size: float = 16, bold: bool = False, italic: bool = False, kerning: bool = True, strike_out: bool = False, underline: bool = False, horizontal_align: str = 'left', vertical_align: str = 'top', wrap: bool = False)#
Text object with associated settings.
- See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#text
and https://doc.mapeditor.org/en/stable/manual/objects/#insert-text
- text#
The text to display
- Type:
str
- color#
Color of the text. (default: (255, 255, 255, 255))
- font_family#
The font family used (default: “sans-serif”)
- Type:
str
- font_size#
The size of the font in pixels. (default: 16)
- Type:
float
- bold#
Whether the font is bold. (default: False)
- Type:
bool
- italic#
Whether the font is italic. (default: False)
- Type:
bool
- kerning#
Whether kerning should be used while rendering the text. (default: False)
- Type:
bool
- strike_out#
Whether the text is striked-out. (default: False)
- Type:
bool
- underline#
Whether the text is underlined. (default: False)
- Type:
bool
- horizontal_align#
Horizontal alignment of the text (default: “left”)
- Type:
str
- vertical_align#
Vertical alignment of the text (defalt: “top”)
- Type:
str
- wrap#
Whether word wrapping is enabled. (default: False)
- Type:
bool
Tile#
- class pytiled_parser.tiled_object.Tile(*, id: int, coordinates: OrderedPair, size: Size = Size(width=0, height=0), rotation: float = 0, visible: bool = True, name: str = '', class_: str = '', properties: Dict[str, Union[float, Path, str, bool, Color]] = {}, gid: int, new_tileset: Optional[Union[Element, Dict[str, Any]]] = None, new_tileset_path: Optional[Path] = None)#
Tile object
See: https://doc.mapeditor.org/en/stable/manual/objects/#insert-tile
- gid#
Reference to a global tile id.
- Type:
int