Tiled files

This forum is currently in read-only mode.
  • 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]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm tying to load objects and its values aka properties but I need help

    for group in mapfile.getElementsByTagName ('objectgroup'):
          for obj in group.getElementsByTagName('object'):
               objName=str(obj.attributes['name'].value)
               objX = int(obj.attributes['x'].value)
               objY = int(obj.attributes['y'].value)
               System.Create (objName, 'obj', objX, objY )
               newobj = eval('SOL.'+objName)
    
    #thats all works, problem is here:
    
               newobj.SetValue ('target', int(obj.properties.attributes['target'].value))
    

    ('target' is object's test var\property in Tiled)

    Actualy, this last line is random, I have no idea what to do

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)