World > Tiled Elements#
TiledWorld exposes tile helper classes for grid-based projects. They are most
useful when you need to inspect or customize tiles, edges, or corners directly.
TileFactory#
TileBase#
- class miniworlds.worlds.tiled_world.tile_elements.TileBase(position, world=None)[source]#
Base class for Tiles and TileDelimiters (like Corners, Edges).
- classmethod from_pixel(pixel_position, world)[source]#
Finds the nearest tile to a given pixel coordinate.
This method uses caching to avoid redundant recalculation of the mapping between tile grid positions and their corresponding pixel coordinates for a given world. It also uses squared distance instead of Euclidean distance for better performance.
- abstract classmethod from_position(position, world)[source]#
Create a tile from a world-relative position.
- Return type:
- static get_local_center_coordinate(world)[source]#
Returns the center point offset for a tile, in local pixel coordinates.
Tile#
- class miniworlds.worlds.tiled_world.tile.Tile(position, world=None)[source]#
- corner_vectors: OrderedDict[str, Tuple[float, float]] = {'no': (-0.5, 0.5), 'nw': (0.5, 0.5), 'so': (-0.5, -0.5), 'sw': (0.5, -0.5)}#
- edge_vectors: dict[str, Tuple[float, float]] = {'n': (0, -0.5), 'o': (0.5, 0), 's': (0, 0.5), 'w': (-0.5, 0)}#
- classmethod from_pixel(pixel_position, world=None)[source]#
Finds the nearest tile to a given pixel coordinate.
This method uses caching to avoid redundant recalculation of the mapping between tile grid positions and their corresponding pixel coordinates for a given world. It also uses squared distance instead of Euclidean distance for better performance.
- classmethod from_position(position, world)[source]#
Create a tile from a world-relative position.
- Return type:
- static get_position_pixel_dict(world)[source]#
Returns a mapping of tile positions to pixel coordinates.
- Return type:
- tile_vectors: dict[str, Tuple[int, int]] = {'no': (-1, 1), 'nw': (1, 1), 'o': (-1, 0), 'so': (-1, -1), 'sw': (1, -1), 'w': (1, 0)}#
Edge#
- class miniworlds.worlds.tiled_world.edge.Edge(position, direction, world)[source]#
- angles: Dict[str, int] = {'n': 3, 'o': 0, 's': 1, 'w': 2}#
- direction_angles: Dict[str, int] = {'n': 90, 'o': 0, 's': 90, 'w': 0}#
- static get_position_pixel_dict(world)[source]#
Returns a mapping of tile positions to pixel coordinates.
- tile_vectors: dict = {'n': [(0, 0.5), (0, -0.5)], 'o': [(-0.5, 0), (0.5, 0)], 's': [(0, 0.5), (0, -0.5)], 'w': [(-0.5, 0), (0.5, 0)]}#
Corner#
- class miniworlds.worlds.tiled_world.corner.Corner(position, direction, world)[source]#
- angles: Dict[str, int] = {'no': 0, 'nw': 1, 'so': 3, 'sw': 2}#
- direction_angles: Dict[str, int] = {'no': 0, 'nw': 0, 'so': 0, 'sw': 0}#
- classmethod from_pixel(position, world=None)[source]#
Finds the nearest tile to a given pixel coordinate.
This method uses caching to avoid redundant recalculation of the mapping between tile grid positions and their corresponding pixel coordinates for a given world. It also uses squared distance instead of Euclidean distance for better performance.