Layer#
This module provides classes for all layer types
There is the base Layer class, which TileLayer, ObjectLayer, ImageLayer, and LayerGroup all derive from. The base Layer class is never directly used, and serves only as an abstract base for common elements between all types.
For more information about Layers, see Tiled’s Manual
Layer#
- class pytiled_parser.layer.Layer(*, name: str, opacity: float = 1, visible: bool = True, repeat_x: bool = False, repeat_y: bool = False, coordinates: OrderedPair = OrderedPair(x=0, y=0), parallax_factor: OrderedPair = OrderedPair(x=1, y=1), offset: OrderedPair = OrderedPair(x=0, y=0), id: Optional[int] = None, class_: Optional[str] = None, size: Optional[Size] = None, properties: Optional[Dict[str, Union[float, Path, str, bool, Color]]] = None, tint_color: Optional[Color] = None)#
Base class that all layer types inherit from. Includes common attributes between the various types of layers. This class will never be returned directly by the parser. It will always return one of the full layer types.
- name#
The name of the layer object.
- Type:
str
- opacity#
Decimal value between 0 and 1 to determine opacity. 1 is completely opaque, 0 is completely transparent. Defaults to 1.
- Type:
float
- visible#
If the layer is visible in the Tiled Editor. Defaults to True
- Type:
bool
- coordinates#
Where layer content starts in tiles. Only used by infinite maps. Defaults to (0, 0).
- parallax_factor#
Used to determine parallaxing speed of a layer. Defaults to (1, 1).
- offset#
Rendering offset of the layer object in pixels. Defaults to (0, 0).
- id#
Unique ID of the layer. Each layer that is added to a map gets a unique id. Even if a layer is deleted, no layer ever gets the same ID.
- Type:
Optional[int]
- size#
Ordered pair of size of map in tiles.
- Type:
Optional[pytiled_parser.common_types.Size]
- properties#
Properties for the layer.
- Type:
Optional[Dict[str, Union[float, pathlib.Path, str, bool, pytiled_parser.common_types.Color]]]
- tint_color#
Tint color that is multiplied with any graphics in this layer.
- Type:
Optional[pytiled_parser.common_types.Color]
- class_#
The Tiled class of this Layer.
- Type:
Optional[str]
- repeat_x#
Repeat drawing on the X Axis(Currently only applies to image layers)
- Type:
bool
- repeat_y#
Repeat drawing on the Y Axis(Currently only applies to image layers)
- Type:
bool
TileLayer#
- class pytiled_parser.layer.TileLayer(*, name: str, opacity: float = 1, visible: bool = True, repeat_x: bool = False, repeat_y: bool = False, coordinates: OrderedPair = OrderedPair(x=0, y=0), parallax_factor: OrderedPair = OrderedPair(x=1, y=1), offset: OrderedPair = OrderedPair(x=0, y=0), id: Optional[int] = None, class_: Optional[str] = None, size: Optional[Size] = None, properties: Optional[Dict[str, Union[float, Path, str, bool, Color]]] = None, tint_color: Optional[Color] = None, chunks: Optional[List[Chunk]] = None, data: Optional[List[List[int]]] = None)#
The base type of layer which stores tile data for an area of a map.
- chunks#
List of chunks (only populated for infinite maps)
- Type:
Optional[List[pytiled_parser.layer.Chunk]]
- data#
A two dimensional array of integers representing the global
- Type:
Optional[List[List[int]]]
- tile IDs for the layer
- Type:
only populaed for non-infinite maps
Chunk#
- class pytiled_parser.layer.Chunk(coordinates: OrderedPair, size: Size, data: List[List[int]])#
Chunk object for infinite maps. Stores data like you would have in a normal TileLayer but only for the area specified by coordinates and size.
- coordinates#
Location of chunk in tiles.
- size#
The size of the chunk in tiles.
- data#
The global tile IDs in the chunk. A row-first two dimensional array.
- Type:
List[List[int]]
ObjectLayer#
- class pytiled_parser.layer.ObjectLayer(*, name: str, opacity: float = 1, visible: bool = True, repeat_x: bool = False, repeat_y: bool = False, coordinates: OrderedPair = OrderedPair(x=0, y=0), parallax_factor: OrderedPair = OrderedPair(x=1, y=1), offset: OrderedPair = OrderedPair(x=0, y=0), id: Optional[int] = None, class_: Optional[str] = None, size: Optional[Size] = None, properties: Optional[Dict[str, Union[float, Path, str, bool, Color]]] = None, tint_color: Optional[Color] = None, tiled_objects: List[TiledObject], draw_order: Optional[str] = 'topdown')#
A Layer type which stores a list of Tiled Objects
- tiled_objects#
List of tiled_objects in the layer.
- Type:
- draworder#
Whether the objects are drawn according to the order of the object elements in the object group element (‘manual’), or sorted by their y-coordinate (‘topdown’). Defaults to ‘topdown’. See: https://doc.mapeditor.org/en/stable/manual/objects/#changing-stacking-order for more info.
ImageLayer#
- class pytiled_parser.layer.ImageLayer(*, name: str, opacity: float = 1, visible: bool = True, repeat_x: bool = False, repeat_y: bool = False, coordinates: OrderedPair = OrderedPair(x=0, y=0), parallax_factor: OrderedPair = OrderedPair(x=1, y=1), offset: OrderedPair = OrderedPair(x=0, y=0), id: Optional[int] = None, class_: Optional[str] = None, size: Optional[Size] = None, properties: Optional[Dict[str, Union[float, Path, str, bool, Color]]] = None, tint_color: Optional[Color] = None, image: Path, transparent_color: Optional[Color] = None)#
A layer type which stores a single image
- image#
The image used by this layer.
- Type:
pathlib.Path
- transparent_color#
Color that is to be made transparent on this layer.
- Type:
Optional[pytiled_parser.common_types.Color]
LayerGroup#
- class pytiled_parser.layer.LayerGroup(*, name: str, opacity: float = 1, visible: bool = True, repeat_x: bool = False, repeat_y: bool = False, coordinates: OrderedPair = OrderedPair(x=0, y=0), parallax_factor: OrderedPair = OrderedPair(x=1, y=1), offset: OrderedPair = OrderedPair(x=0, y=0), id: Optional[int] = None, class_: Optional[str] = None, size: Optional[Size] = None, properties: Optional[Dict[str, Union[float, Path, str, bool, Color]]] = None, tint_color: Optional[Color] = None, layers: Optional[List[Layer]])#
A layer that contains layers (potentially including other LayerGroups, nested infinitely).
In Tiled, offset and opacity recursively affect child layers, however that is not enforced during parsing by pytiled_parser, and is up to the implementation how to handle recursive effects of LayerGroups
- layers#
list of layers contained in the group.
- Type:
Optional[List[pytiled_parser.layer.Layer]]