Tiled files

For questions about using Classic.

Post » Sat Nov 06, 2010 10:46 pm

[quote:uvjw97xw]If there is it would only be at the start of the layout.[/quote:uvjw97xw]
Oh, nice, i thought it would draw it on every frame xD.

Wow it worked!
B
2
G
2
Posts: 32
Reputation: 714

Post » Sun Nov 07, 2010 6:10 am

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...
B
94
S
37
G
11
Posts: 404
Reputation: 11,275

Post » Sun Nov 07, 2010 7:23 am

[quote="R0J0hound":20gmdjnk]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.
[url:20gmdjnk]http://dl.dropbox.com/u/5426011/examples2/tilemapLoad.cap[/url:20gmdjnk]
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:20gmdjnk]
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!

[quote="Candescence":20gmdjnk]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...[/quote:20gmdjnk]

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...
B
2
S
2
G
3
Posts: 143
Reputation: 1,536

Post » Sun Nov 07, 2010 7:38 am

[quote:3qxdgnrk]How the hell do you get proper alpha right off the bat with these things?[/quote:3qxdgnrk]
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...[/quote:3qxdgnrk]
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:
[code:3qxdgnrk]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]
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

Post » Sun Nov 07, 2010 7:59 am

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?
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,849
Reputation: 48,299

Post » Sun Nov 07, 2010 8:21 am

Ah, thanks! This is much better! :D

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.
B
94
S
37
G
11
Posts: 404
Reputation: 11,275

Post » Thu Jun 02, 2011 8:08 pm

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.


[code:w9yt9x0n]
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]
B
4
G
3
Posts: 39
Reputation: 978

Post » Thu Jul 21, 2011 6:38 pm

I'm tying to load objects and its values aka properties but I need help
[code]
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))
[/code]
('target' is object's test var\property in Tiled)
Actualy, this last line is random, I have no idea what to doDtrQ2011-07-21 18:41:14
B
2
S
2
G
2
Posts: 158
Reputation: 1,366

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests