pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Tiled TMX Loader

Tiled TMX Loader - v.11

Leif Theden (bitcraft)

Tags:

Description

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.

Features:
    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)

===============================================================================

Just data
---------

    >>> 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.

https://github.com/bitcraft/pyscroll

===============================================================================

The 16x16 overworld tiles were created by MrBeast at opengameart.org. CC-BY 3.0

Links

Home Page: https://github.com/bitcraft/PyTMX
Source: https://github.com/bitcraft/PyTMX

Screenshot


click to view original size

Releases

Tiled TMX Loader - 3.19.3 - Sep 17, 2014
Tiled TMX Loader - v.15 - May 31, 2012
Tiled TMX Loader - v.14 - May 10, 2012
Tiled TMX Loader - v.13 - Mar 20, 2012
Tiled TMX Loader - v.11 - Feb 20, 2012

Pygame.org account Comments

If you wish to leave a comment with your pygame.org account, please sign in first.

December 8, 2011 10:50pm - Leif Theden - nickname: (bitcraft)
milleja46: i cannot test this on python 3.x.
November 15, 2011 2:48pm - Josh Miller - nickname: (milleja46)
Still doesn't work...the import of it works fine.
The problem is doing "tiledmap = tmxloader.load_pygame("test.tmx")" it reports a error with str and bytes which shouldn't happen since test.tmx is a filename...(this is the python 3 version you gave me)
November 1, 2011 3:13pm - Leif Theden - nickname: (bitcraft)
@milleja46 I am not able to reproduce this, but I realize what caused it. I'll have a fixed version up soon. Thanks for the report.
October 31, 2011 10:15am - Josh Miller - nickname: (milleja46) - 2/5
I try and run it and i get:
"Traceback (most recent call last):
File "E:\Documents\gameEngine\gameEngine.py", line 5, in <module>
import tmxloader
File "E:\Documents\gameEngine\tmxloader.py", line 136
except IndexError, ValueError:
^
SyntaxError: invalid syntax"

So it doesn't work and i've not even tried using a map made in tiled o_o
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Oct 21, 2014


Oct 20, 2014

Oct 16, 2014

Oct 9, 2014

Oct 8, 2014

Oct 7, 2014

Oct 4, 2014

Oct 1, 2014

Sep 19, 2014

Sep 17, 2014

Sep 9, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)