Tiled Map Reader

arcade.tilemap.TileMap

class arcade.tilemap.TileMap(map_file: Union[str, pathlib.Path], scaling: float = 1.0, layer_options: Optional[Dict[str, Dict[str, Any]]] = None, use_spatial_hash: Optional[bool] = None, hit_box_algorithm: str = 'Simple', hit_box_detail: float = 4.5)[source]

Class that represents a fully parsed and loaded map from Tiled. For examples on how to use this class, see: https://arcade.academy/examples/index.html#using-tiled-map-editor-to-create-maps

Attributes:
tiled_map

The pytiled-parser map object. This can be useful for implementing features that aren’t supported by this class by accessing the raw map data directly.

width

The width of the map in tiles. This is the number of tiles, not pixels.

height

The height of the map in tiles. This is the number of tiles, not pixels.

tile_width

The width in pixels of each tile.

tile_height

The height in pixels of each tile.

background_color

The background color of the map.

scaling

A global scaling value to be applied to all Sprites in the map.

sprite_lists

A dictionary mapping SpriteLists to their layer names. This is used for all tile layers of the map.

object_lists

A dictionary mapping TiledObjects to their layer names. This is used for all object layers of the map.

get_cartesian(x: float, y: float) Tuple[float, float][source]

Given a set of coordinates in pixel units, this returns the cartesian coordinates.

This assumes the supplied coordinates are pixel coordinates, and bases the cartesian grid off of the Map’s tile size.

If you have a map with 128x128 pixel Tiles, and you supply coordinates 500, 250 to this function you’ll receive back 3, 2

Parameters
  • x (float) – The X Coordinate to convert

  • y (float) – The Y Coordinate to convert

arcade.tilemap.load_tilemap

arcade.tilemap.load_tilemap(map_file: Union[str, pathlib.Path], scaling: float = 1.0, layer_options: Optional[Dict[str, Dict[str, Any]]] = None, use_spatial_hash: Optional[bool] = None, hit_box_algorithm: str = 'Simple', hit_box_detail: float = 4.5) arcade.tilemap.tilemap.TileMap[source]

Given a .json map file, loads in and returns a TileMap object.

A TileMap can be created directly using the classes __init__ function. This function exists for ease of use.

For more clarification on the layer_options key, see the __init__ function of the TileMap class

Parameters
  • map_file (Union[str, Path]) – The JSON map file.

  • scaling (float) – The global scaling to apply to all Sprite’s within the map.

  • use_spatial_hash (Optional[bool]) – If set to True, this will make moving a sprite in the SpriteList slower, but it will speed up collision detection with items in the SpriteList. Great for doing collision detection with static walls/platforms.

  • hit_box_algorithm (str) – One of ‘None’, ‘Simple’ or ‘Detailed’.

  • hit_box_detail (float) – Float, defaults to 4.5. Used with ‘Detailed’ to hit box.

  • layer_options (Dict[str, Dict[str, Any]]) – Layer specific options for the map.

arcade.tilemap.read_tmx

arcade.tilemap.read_tmx(map_file: Union[str, pathlib.Path]) pytiled_parser.tiled_map.TiledMap[source]

Deprecated function to raise a warning that it has been removed.

Exists to provide info for outdated code bases.