I added multiple tilesets to this just for the heck of it.
The sprites with the tilesets need to be named according to the names in the Tiled file, or it won't work.
from xml.dom import minidom
#from array import array
#mapfile = minidom.parse(System.AppPath + 'ConstructTestMap.tmx')
mapfilename = System.globalvar('TilesetFile')
Spritename = '';
mapfile = minidom.parse(System.AppPath + mapfilename)
a = mapfile.getElementsByTagName('map')[0]
width = int(a.attributes['width'].value)
height = int(a.attributes['height'].value)
tilewidth = int(a.attributes['tilewidth'].value)
tileheight = int(a.attributes['tileheight'].value)
TSlook = {}
#load all tilesets
for tileset in mapfile.getElementsByTagName('tileset'):
tsfirstid = int(tileset.attributes['firstgid'].value)
tsname = str(tileset.attributes['name'].value)
Debug.SetText(repr(tsname))
TSlook[tsname] = tsfirstid
#load all layers
layernum=1
for layer in mapfile.getElementsByTagName('layer'):
index=0
for tile in layer.getElementsByTagName('tile'):
val = int(tile.attributes['gid'].value)
if val > 0:
# find out what spritesheet to get sprite from.
lastchecked = 0
for k,v in TSlook.iteritems():
if val>=v and lastchecked <v:
lastchecked = v
Spritename = k
System.Create(Spritename,layernum,0,0)
Spriteobj = eval('SOL.' + Spritename)
if layernum==3:
Spriteobj.SetCollisionMode(3)
Spriteobj.x = (index % width) * tilewidth
Spriteobj.y = (index / width) * tileheight
Spriteobj.SetAnimFrame(val - lastchecked + 1)
index+=1
layernum+=1
[/code:w9yt9x0n]