pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
map loader for 'tiled'

map loader for 'tiled' - 1.1

DR0ID (dr0id)

Tags:

Description

Map loader for the files generated by Tiled, the map editor originally written in java. Today a implementation in C++ using QT is available.

'tiledtmxloader' loads the *.tmx files from Tiled. This library includes also a python renderer for orthogonal maps (isometric and hexagonal maps can be loaded, but there is not renderer implemented).

dependencies:
python 2.6+
pygame 1.9.1+

license for 'tiledtmxloader': New BSD license

license for demo map and tilesets in the examples: GPL2+
(thanks to The Mana World )

Changes

bugfix loading value attributes of property nodes

Links

Home Page: https://code.google.com/p/pytmxloader/
Source: http://dr0id.homepage.bluewin.ch/pygame/tiledtmxloader.zip

Screenshot


click to view original size

Releases

map loader for 'tiled' - 3.0.3 - Dec 14, 2011
map loader for 'tiled' - 2.2 - Jan 16, 2011
map loader for 'tiled' - 2.1.1 - Nov 21, 2010
map loader for 'tiled' - 2.1.1 - Jul 14, 2010
map loader for 'tiled' - 2.1 - Jun 22, 2010
map loader for 'tiled' - 2.1 - Jul 23, 2009
map loader for 'tiled' - 2.0 - Jul 19, 2009
map loader for 'tiled' - 1.1 - Jul 16, 2009
map loader for 'tiled' - 1.0 - Jun 9, 2009

Pygame.org account Comments

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

March 19, 2011 5:39am - DR0ID - nickname: (dr0id)
thanks, fixed in trunk (see issue 8)
March 14, 2011 8:33pm - Zach Rogers - nickname: (zachr) - 5/5
The function def load_image_part in the ImageLoaderPyGame(IImageLoader) should be as follows to fix the issue with the transparency key(colorkey) not working correctly:

def load_image_part(self, filename, x, y, w, h, colorkey=None):
source_img = self.load_image(filename, colorkey)
## ISSUE 4:
## The following usage seems to be broken in pygame (1.9.1.):
## img_part = self.pygame.Surface((tile_width, tile_height), 0, source_img)
img_part = self.pygame.Surface((w, h), source_img.get_flags(), source_img.get_bitsize())
source_rect = self.pygame.Rect(x, y, w, h)

#Set the colorkey BEFORE we blit the source_img
if colorkey:
img_part.set_colorkey(colorkey, self.pygame.RLEACCEL)
img_part.fill(colorkey)

img_part.blit(source_img, (0, 0), source_rect)

return img_part
January 16, 2011 9:04am - DR0ID - nickname: (dr0id)
@ep8kha very thanks, your hints were really useful and correct.

version 2.2 is out, check it out!
December 19, 2010 1:24am - George - nickname: (ep8kha)
@mayec I believe you need to change what type of data the Tile Layer is stored as. If you go to Edit->Preference in Tiled, there's a drop down menu titled "Store tile layer data as." If the selection is anything other than "Base64(uncompressed)" or "Base64(gzip compressed)", an error will be flagged. For the particular error you've posted, "XML" seems to be the selection for your tmx file.

@DR0ID It seems that the following lines of code in the decode method in the TileLayer Class is not throwing an exception for tmx files where the tile layered is stored as XML:

s = self.encoded_content
if self.encoded_content:
if self.encoding:
if self.encoding == u'base64':
s = decode_base64(s)
else:
raise Exception(u'unknown data encoding %s' % (self.encoding))
if self.compression:
if self.compression == u'gzip':
s = decompress_gzip(s)
else:
raise Exception(u'unknown data compression %s' %(self.compression))
else:
raise Exception(u'no encoded content to decode')

It seems that "self.encoded_content" has a value for those files, so it passes through "if self.encoded_content" line. However, it never goes into the two nested if statements thereafter, even though it's an unsupported file. Hope this helps!
November 21, 2010 4:12am - DR0ID - nickname: (dr0id)
Hello Rohin Knight
I have tried what you suggested, but it did not work. If you have still an problem, could you provide me an example so I can test it?
Thanks for reporting back. From now on you can report issues on the project homepage on https://code.google.com/p/pytmxloader/
October 22, 2010 1:53am - Rohin Knight - nickname: (rohin)
This is a really awesome lib and has saved me a lot of time.

I thought I might just point out one bug I found:
On lines 151 and 152, replace these two lines:


for y in xrange(margin, h, tile_height + spacing):
for x in xrange(margin, w, tile_width + spacing):


...with these two lines...


for y in xrange(margin, h - tile_height, tile_height + spacing):
for x in xrange(margin, w - tile_width, tile_width + spacing):
June 18, 2010 1:26pm - DR0ID - nickname: (dr0id)
Sorry for the long delay!
@ mayec: I would need to get such a tmx file to test against it and debug it. I'm often on the #pygame chat (see: http://pygame.org/wiki/info#IRC )
June 18, 2010 1:24pm - DR0ID - nickname: (dr0id)
Sorry for the long delay!

@ hobo: there is a demo integrated into the file, see (for pygame):
http://code.google.com/p/python-pyknic/source/browse/trunk/pyknic_old/pyknic/resources/tiledtmxloader.py#858

or for pyglet:

http://code.google.com/p/python-pyknic/source/browse/trunk/pyknic_old/pyknic/resources/tiledtmxloader.py#957
June 15, 2010 7:26pm - Mad Cloud Games - nickname: (madcloudgames)
are there any SIMPLE code examples that would show how to implement this?
Ive looked through the documentation and the code a few times but from the view of a novice programmer, its all very confusing. I would love to be
able to use this but I just dont know how..
March 16, 2010 5:38pm - Thomas Kowaliczek - nickname: (linuxdonald)
There you can find the lastest version of maybe that helps you.
IÂŽm not the code of this.

http://code.google.com/p/python-pyknic/source/browse/#svn/trunk/pyknic_old/pyknic/resources
February 21, 2010 9:57am - Mayec Rancel - nickname: (mayec)
Some tmx files open fine, but when trying to decode certain .tmx files, I get the following error:

__main__ loading ...
Traceback (most recent call last):
File "tiledtmxloader.py", line 1011, in <module>
main()
File "tiledtmxloader.py", line 1001, in main
demo_pygame(args[0])
File "tiledtmxloader.py", line 839, in demo_pygame
world_map = TileMapParser().parse_decode(file_name)
File "tiledtmxloader.py", line 822, in parse_decode
world_map.decode()
File "tiledtmxloader.py", line 402, in decode
layer.decode()
File "tiledtmxloader.py", line 577, in decode
(ord(str(s[idx + 2])) << 16) | (ord(str(s[idx + 3])) << 24)
IndexError: string index out of range
November 9, 2009 3:20pm - Fredrik Corneliusson - nickname: (tomten)
Great lib!
I just converted my game to use this lib and it was actually quite simple thanks to the good quality and documentation.
http://code.google.com/p/turb-game/

Just what I needed so I could skip to doing the fun stuff in my game!
August 30, 2009 4:42am - Nils Fagerburg - nickname: (nils) - 5/5
I know I already said this, but this is really a wonderful little library. Thanks again.
August 18, 2009 1:03pm - Federico Ramirez - nickname: (fedekun) - 5/5
Awasome :)
Thanks a lot for sharing
August 11, 2009 12:11am - Alia M - nickname: (alia) - 4/5
Nice work :)
July 5, 2009 8:12pm - Nils Fagerburg - nickname: (nils)
Awesome!
Thanks for sharing this.
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
May 24, 2013


May 23, 2013

May 22, 2013


May 21, 2013

May 19, 2013

May 18, 2013


May 17, 2013

May 16, 2013

May 15, 2013

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