Tiled TMX Loader
Tiled TMX Loader - 3.19.3
Leif Theden (bitcraft)
Map loader for TMX Files
Leif Theden (bitcraft), 2011-2014
v3.19.3 - for python 2.7 and 3.3+
If you have any problems or suggestions, please open an issue on the github page.
I am also often lurking #pygame on freenode. Feel free to contact me.
released under the LGPL v3
PyTMX is a map loader for python/pygame designed for games. It provides smart
tile loading with a fast and efficient storage base. Not only will does it
correctly handle most Tiled object types, it also will load metadata for
them, so you can modify your maps and objects in Tiled, instead of modifying
your source code.
API with many handy functions
Properties metadata for all native Tiled object types
Point data for polygon and polyline objects
Automatic flipping and rotation of tiles
Supports base64, csv, gzip, zlib and uncompressed XML
Image loading with pygame (works ok without pygame)
>>> import pytmx
>>> tmxdata = pytmx.TiledMap("map.tmx")
Load with Pygame Surfaces
>>> from pytmx import load_pygame
>>> tmxdata = load_pygame("map.tmx")
The loader will correctly convert() or convert_alpha() each tile image, so you
don't have to worry about that after you load the map.
Getting the Tile Surface
>>> image = tmx_data.get_tile_image(x, y, layer)
>>> screen.blit(image, position)
Getting Object Properties
>>> tmxdata = TiledMap('level1.tmx')
>>> props = txmdata.get_tile_properties(x, y, layer)
>>> props = tmxdata.get_layer_by_name("dirt").properties
Using Raw XML
It is possible to load TiledMap object from XML strings.
>>> tmxdata = TiledMap.from_string(xml_string)
I have another repo with a working demo of a proper scrolling map using Tiled
maps. Please feel free to test drive it. It isn't limited to Tiled maps,
you can use any data structure you want, as long as PyGame is used.
The 16x16 overworld tiles were created by MrBeast at opengameart.org. CC-BY 3.0
New in 3.19:
core: new iterator for tiledmap
core: objects/shapes load the rotation value
core: polygon/polyline and all other shapes return coordinates as float
core: pytmx respects tiles that specify external image stored in metadata
core: tileoffsets are loaded stored in tileset.offset: tuple: (x, y)
core: logging module used everywhere
pygame: tilesets can be loaded even if they don't specify an image
pygame: loader has new logger...more descriptive error messages
pygame: loading of tiles that specify an external image is supported
pygame: new optional arguments for load_pygame():
load_all: bool (False is default), load al tiles, even unused ones
optional_gids: list/tuple, also load the gids in this list
'gid' refers to the gid found in tiled
click to view original size
Pygame.org account Comments
If you wish to leave a comment with your pygame.org account, please sign in first.
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
Aug 24, 2016
Aug 3, 2016
Aug 2, 2016
Aug 1, 2016
Jul 29, 2016
Jul 24, 2016
Jul 1, 2016