Diddy and Tiled: how to save or convert to xml?

Monkey Forums/Monkey Programming/Diddy and Tiled: how to save or convert to xml?

Amon(Posted 2012) [#1]
Is the Diddy capable of loading maps saved with Tiled? If so what preferences should be set in Tiled in order to successfully load a tilemap in to my Monkey project?

Also, I have not seen an xml export so how would I go about converting Tiled Exported maps to xml and allowing them to be readable by Diddy's Map Loading routines?

1024 Thank Yous!


therevills(Posted 2012) [#2]
Yep, Diddy can load in a Tiled map. Samah did a great job there. Check out the platformer example and also the tiled example included in Diddy.

When you save your map in Tiled, it saves it as an TMX file, which is just a XML file.


Amon(Posted 2012) [#3]
Hey! I'm consistently getting the same error when trying to load the map. It keeps pointing to this line in tile.monkey: line 452:

If tl.maxTileWidth < tiles[tl.mapData.tiles[i] - 1].width Then tl.maxTileWidth = tiles[tl.mapData.tiles[i] - 1].width


		' calculate the max tile size per layer
		For Local l:TileMapLayer = Eachin layers
			If TileMapTileLayer(l) <> Null Then
				Local tl:TileMapTileLayer = TileMapTileLayer(l)
				For Local i% = 0 Until tl.mapData.tiles.Length
					If tl.mapData.tiles[i] > 0 Then
						If tl.maxTileWidth < tiles[tl.mapData.tiles[i] - 1].width Then tl.maxTileWidth = tiles[tl.mapData.tiles[i] - 1].width
						If tl.maxTileHeight < tiles[tl.mapData.tiles[i] - 1].height Then tl.maxTileHeight = tiles[tl.mapData.tiles[i] - 1].height
					End
				Next
			End
		Next
	End


I've looked at the examples and I'm sure it should work but I'm unable to figure out yet what I'm doing wrong. To make sure it does work I'll try the platform example and will edit this post with the result.

While this has been bugging me I've made a lot of progress on other parts of the game but ideally I'd like to return to this and start making the levels.

Ta!

[edit]Yeh those examples work fine. Gonna study the preferences used for the level.tmx in the platform example. I know Raw XML is not supported so will try csv or one of the 3 Base64 Encoders to see what config works.


NoOdle(Posted 2012) [#4]
Hi amon, I have written a TMX loader for my framework (still not released yet unfortunately). I was wondering if you would mind If I tried to load your map with my code? It might highlight an issue with Diddy or with how the map has been constructed. Will be interesting to see if my loader crashes too! If you want to and don't mind sending me the files, you can use the email in my profile. (My loader can handle raw xml, csv or base64 so as long as the data is in one of those formats it will be fine.)


therevills(Posted 2012) [#5]
Could you post the TMX file here (with codebox tags)?

We originally didnt support the Raw XML output due to the slowness of the XML parser, I can't remember if that was changed after Samah gave it a speed boost...


Amon(Posted 2012) [#6]
Hi! Here is a test .tmx? http://www.amon.co/storage/test.tmx

Even this simple one fails! Thanks for having a look.


therevills(Posted 2012) [#7]
Strange... works fine here. What is the exact error you are getting?

Also can you post your source code?


Amon(Posted 2012) [#8]
hmm! I get an 'Array Index Out of Bounds Error'. I am using a nightly build of Tiled though for windows.

I'll post the code I'm using in a bit; got to do a few things on some other part of the game for now. Won't be long!

Thanks for testing it though anyway.


NoOdle(Posted 2012) [#9]
Im not familiar with Diddy's TMX loader but I wondered if the image source could be pointing to an invalid location?
image source="../graphics/mblocks.png



therevills(Posted 2012) [#10]
Nope thats fine, and if the Tile loader can not load the resource you get a nice error message saying so ;)


Amon(Posted 2012) [#11]
Ok! I figured out what was going on. If I load the images in with game.images.Load at the start of my code where I load all other graphics then I get the 'out of bounds' error.

If I comment out the loading of the tileset image and leave it for Diddy to load the gfx with the map then it works without error.

game.images.LoadAnim("mblocks.png", 96, 96, 12, tmpImage, True, False)


So commenting out the above from "loadImages" will make it compile, run and lets me see the TileMap.

Why? Dunno!


therevills(Posted 2012) [#12]
Hmmm, I'll look into it as it shouldn't crash like it did. Glad you worked it out though :)


Amon(Posted 2012) [#13]
Looking forward to the update because as it stands I have to have 2 sets of the same image. One set for Diddy to load automatically with the Tiled tilemap and another to use in LoadImage.

I need the one in loadimage for things not associated with the tilemap.


therevills(Posted 2012) [#14]
Fixed.

Now if you load in the image via:
[monkeycode]game.images.LoadAnim("mblocks.png", 96, 96, 12, tmpImage, True, False)[/monkeycode]

And if you use the same image in your Tile map, Diddy will overwrite the previously loaded image with the one in the XML.


Amon(Posted 2012) [#15]
Cool! Thanks!