Tiled files

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Each tile 64 by 64 pixels - Ultimate Tile Set for your awesome games
  • I'm new here, trying to see if construct can fit my needs for my project. My project relies on many tile maps. Is it possible to load Tile map files from http://www.mapeditor.org/ into construct?

  • I don't think Construct has that ability naturally, but it says on Tiled's sight that the info is stored in an xml. As long as the images are stored outside the program as well (so they could be loaded into Construct) I'm sure it can be done.

    If you're willing to upload a pack of the pictures including a screenshot of what the end product should look like, and the .xml file I'll give it a shot.

  • This is pretty much THE reason why I've been clamoring for a Tiled Plugin for a while, now. It would certainly make tile-based level design a LOT easier.

  • That would be great, what I'm offering is an example of doing it event sheet though.. maybe with python.

    But I second the nomination for a plugin!

  • Okay... I might prepare a quick tile map and tile sheet, and send the whole thing over to you so you can try your hand at doing it with events, I probably wouldn't be able to figure it out, myself.

  • I hope this works out ^^

    But how would performance go? After all python can be a bit sluggish.

  • I hope this works out ^^

    But how would performance go? After all python can be a bit sluggish.

    If there is it would only be at the start of the layout.

    Also someone should check this out if your serious.

    http://construct.svn.sourceforge.net/viewvc/construct/Plugins/Tileset/

  • Alright, I made a quick tile map, with a tilesheet, the native Tiled file, and an XML file.

    Let's see if we can get this working via events and/or Python.

  • Python is the ideal route to take as it has good xml support.

    Here is a cap that will load the map that Candescence posted in the previous post.

    http://dl.dropbox.com/u/5426011/examples2/tilemapLoad.cap

    made in 0.99.96

    Be sure to put the cap in the same directory as the map. Also you might need to install python because the xml modules aren't included in construct.

  • [quote:uvjw97xw]If there is it would only be at the start of the layout.

    Oh, nice, i thought it would draw it on every frame xD.

    Wow it worked!

  • However, irritatingly, alpha doesn't work because Construct doesn't seem to like the way Paint.Net saves alpha. I had to remove the black stuff manually. Ugh, what a pain. Don't use Paint.Net for alpha in PNGs, folks.

    Edit: Or GIMP either, apparently. God dammit. How the hell do you get proper alpha right off the bat with these things?

    Now, the next main problem to make this viable is Z-Order. In other words, layers. Oh, yeah, and collision, I forgot. You either want some things to collide, or some things to not collide, basically...

    ... Then again, for collision, you could just have a second tileset for collision stuff. That works well. Z-Order is still a problem, though.

    Edit: Also, you want to be able to work with multiple tile sets at once, and by consequence, multiple sprites. So, basically...

  • Python is the ideal route to take as it has good xml support.

    Here is a cap that will load the map that Candescence posted in the previous post.

    http://dl.dropbox.com/u/5426011/examples2/tilemapLoad.cap

    made in 0.99.96

    Be sure to put the cap in the same directory as the map. Also you might need to install python because the xml modules aren't included in construct.

    That works very well. A much more elegant approach then I took. I managed to get a result but without the module so my code was much longer and messier. Python has an XML parser? You learn something new everyday!

    However, irritatingly, alpha doesn't work because Construct doesn't seem to like the way Paint.Net saves alpha. I had to remove the black stuff manually. Ugh, what a pain. Don't use Paint.Net for alpha in PNGs, folks.

    Edit: Or GIMP either, apparently. God dammit. How the hell do you get proper alpha right off the bat with these things?

    Now, the next main problem to make this viable is Z-Order. In other words, layers. Oh, yeah, and collision, I forgot. You either want some things to collide, or some things to not collide, basically...

    ... Then again, for collision, you could just have a second tileset for collision stuff. That works well. Z-Order is still a problem, though.

    Edit: Also, you want to be able to work with multiple tile sets at once, and by consequence, multiple sprites. So, basically...

    I managed to get collision working in my script, but it basically involved cloning the tileset and adding the 'Solid' attribute to it. I then added a python list which had all the values for solid tiles and ran a simple condition which decided on which sprite to draw. And it seems that if you import an image by splitting it, it ignores the transparency :/

    Unfortunately, creating a tile editor through Python just isn't a viable method if you don't know Python or want to create a semi-complex game. For a truly flexible approach, one needs to create a plugin which is able to add the individual objects into the layout editor as it allows for more flexibility, but that's no easy task...

  • [quote:3qxdgnrk]How the hell do you get proper alpha right off the bat with these things?

    Convert the color mode of the PNG from Indexed to RGB. Then the transparency is preserved when the image is imported.

    [quote:3qxdgnrk]Now, the next main problem to make this viable is Z-Order. In other words, layers. Oh, yeah, and collision, I forgot. You either want some things to collide, or some things to not collide, basically...

    Z-Ordering is easy, just load each layer to a different layer.

    For collisions just set the collision mode for all the sprites on one layer to per-pixel and none on the other layers.

    Give the Sprite the Solid attribute and set it's collision mode to none.

    Here's a updated script:

    from xml.dom import minidom
    
    mapfile = minidom.parse(System.AppPath + 'ConstructTestMap.tmx')
    
    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)
    
    #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:
    			System.Create('Sprite',layernum,0,0)
    			if layernum==2:
    				SOL.Sprite.SetCollisionMode(3) # 3 is per-pixel
    			SOL.Sprite.x=(index % width) * tilewidth 
    			SOL.Sprite.y=(index / width) * tileheight
    			SOL.Sprite.SetAnimFrame(val)
    		index+=1
    	layernum+=1[/code:3qxdgnrk]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry if this is a dumb question, but if I use this method of map creation - using python to read the xml - then would any recipient of the cap file or completed game need to have python installed also?

  • Ah, thanks! This is much better!

    Okay, looks like the last thing we need is incorporating multiple tile sets, and then we're ready.

    But, I do concur with Shady - if we want to implement Tiled maps without it being too much of a hassle to test and stuff, we'll need a plugin.

    Edit: Here's a zip file containing all the files needed, plus an updated cap with not only the updated script, but a platforming thing to show that the collision does work.

    However, Python scripting in general epically fails in my own project, so I'm not gonna use it, and instead wait for someone to make a plugin.

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