pygame is
spacer
spacer
 
 
pygame.org is
spacer
spacer
spacer
Tiled TMX Loader

Tiled TMX Loader - v.13

Leif Theden (bitcraft)

Tags:

pygame tiled tmx lib2d

Description

Map loader for TMX Files
bitcraft (leif dot theden at gmail.com)
v.13 - for python 2.7

If you have any problems or suggestions, please contact me via email.
Tested with Tiled 0.8.0 for Mac.

released under the GPL v3

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

This map loader can be used to load maps created in the Tiled map editor.  It
provides a simple way to get tiles and associated metadata so that you can draw
a map onto the screen.

This is *not* a rendering engine.  It will load the data that is necessary to
render a map onto the screen.  All tiles will be loaded into in memory and
available to blit onto the screen.


Design Goals:
    Simple api
    Memory efficient and fast

Features:
    Loads data and "properties" metadata from Tile's TMX format
    "Properties" for: maps, tilesets, layers, objectgroups, objects, and tiles
    Automatic flipping and rotation of tiles
    Supports base64, csv, gzip, zlib and uncompressed TMX
    Image loading with pygame

Missing:
    Polyline (new in 0.8.0)
    Polygon (new in 0.8.0)


New in .13:
    loader: Renamed "get_tile_image" to "getTileImage"
    loader: Removed duplicates returned from getTilePropertiesByLayer
    loader: Modified confusing messages for GID errors
    loader: Fixed bug where transformed tile properties are not available
    loader: No longer loads metadata for tiles that are not used
    loader: Reduced tile cache to 256 unique tiles
    loader: Removed 'visible' from list of reserved words
    loader: Added 'buildDistributionRects' and maputils module
    loader: Added some misc. functions for retrieving properties
    pygame: Smarter tile management made tile loading cache useless; removed it
    pygame: pygame.RLEACCEL flag added when appropriate

New in .12:
    loader: Fixed bug where tile properties could contain reserved words
    loader: Reduced size of image index by only allocating space for used tiles

New in .11:
    loader: Added support for tileset properties
    loader: Now checks for property names that are reserved for internal use
    loader: Added support for rotated tiles
    pygame: Only the tiles that are used in the map will be loaded into memory
    pygame: Added support for rotated tiles
    pygame: Added option to force a bitsize (depth) for surfaces
    pygame: Added option to convert alpha transparency to colorkey transparency
    pygame: Tilesets no longer load with per-pixel alphas by default
    pygame: Colorkey transparency should be correctly handled now


NOTES:

* The Tiled "properties" have reserved names.

If you use "properties" for any of the following object types, you cannot use
any of theese words as a name for your property.  A ValueError will be raised
if there are any conflicts.

As of 0.8.0, these values are:

map:        version, orientation, width, height, tilewidth, tileheight
            properties, tileset, layer, objectgroup

tileset:    firstgid, source, name, tilewidth, tileheight, spacing, margin,
            image, tile, properties

tile:       id, image, properties

layer:      name, x, y, width, height, opacity, properties, data

objectgroup: name, color, x, y, width, height, opacity, object, properties

object:     name, type, x, y, width, height, gid, properties, polygon,
            polyline, image



I have been intentionally not including a rendering utility since rendering a
map will not be the same in every situation.  However, I can appreciate that
some poeple won't understand how it works unless they see it, so I am including
a sample map and viewer.

I've included a copy of this loader that may work with python 3.x.  I
personally do not think that python 3.x should be used with pygame, yet (and I
am not the only person).  You can try it if you insist on using pygame with
python 3.x, but I don't update that often.

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

Basic usage sample:

    >>> import tmxloader
    >>> tmxdata = tmxloader.load_pygame("map.tmx")


When you want to draw tiles, you simply call "get_tile_image":

    >>> image = tmxdata.getTileImage(x, y, layer)    
    >>> screen.blit(position, image)


Maps, tilesets, layers, objectgroups, and objects all have a simple way to
access metadata that was set inside tiled: they all become object attributes.

    >>> layer = tmxdata.layers[0]
    >>> print layer.tilewidth
    32
    >>> print layer.weather
    'sunny'


Tiles properties are the exception here, and must be accessed through
"getTileProperties".  The data is a regular Python dictionary:

    >>> tile = tmxdata.getTileProperties(x, y, layer)
    >>> tile["name"]
    'CobbleStone'

Changes

Lots of internal changes and performance fixes.

See changelog in readme.

Links

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

Screenshot

spacer
click to view original size

Releases

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
spacer
PyGameZine - issue0

spacer
QANAT - 0.5
 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Mar 21, 2012
spacer
AK360 - 1.0

Mar 20, 2012
spacer
Tiled TMX Loader - v.13

Mar 19, 2012
spacer
miniKar - 0.01

Mar 18, 2012
spacer
Jelly - 1.0

Mar 17, 2012
spacer
Starheaven - 0.0.7

Mar 16, 2012
spacer
ultimate game collection - final

Mar 14, 2012
spacer
Pong Dexule Internet Lan Multiplayer - 0.1

Mar 12, 2012
spacer
Random Terrain Generator - 1.0

spacer
Hit_The_Mice - 1.0

Mar 11, 2012
spacer
Of Cabbages and Kings - 1.01

Mar 10, 2012
spacer
Python PyGame Tower Defence - 0.8.0

spacer
University of Python - 0.1

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.