Tiled TMX Loader
Tiled TMX Loader - v.14
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 .14:
loader: Fixed gid lookup for "buildDistributionRects"
loader: Added useful output to a few classes "__repr__"
pygame: fixed colorkey handling
pygame: correctly handles margins and spacing between tiles in tilesets
pygame: b/c of changes, now correctly renders tiled's example maps
added scrolling demo
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.
Feb 1, 2015
Jan 28, 2015
Jan 24, 2015
Jan 20, 2015
Jan 15, 2015
Jan 14, 2015
Jan 7, 2015
Jan 4, 2015