Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Program Announcements / TMX importer

Author
Message
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st May 2013 11:42 Edited at: 7th May 2013 08:31
TMX files are XML files created by Tiled, a nifty program for building 2D tile maps.

AGK version here.

As simple as this was, I'm surprised it hasn't been done yet.(although it was discussed in an old thread) There's a few things I need to add to the code before releasing the library, including comments since I didn't write any! But it's pretty straight forward and uses my XML library, which I added a few commands that aren't shown in that snippet.

I used the example map found here:
http://gamedev.tutsplus.com/tutorials/implementation/parsing-tiled-tmx-format-maps-in-your-own-game-engine/

Though that site has code for an importer, this is very much my own. AS3 and DB are just too different, but the code is pretty straight forward.

This won't load base64 map files. So be sure to go under edit-preferences and store tile layer data as xml.

Here's a screenshot of a loaded map. The lines you see aren't a problem with the importer, it's just how the map was created. (I wasted 45min trying to figure that out!) The transparent box shows collision boundaries that were setup in the map as well.



"You're all wrong. You're all idiots." ~Fluffy Rabbit

Attachments

Login to view attachments
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd May 2013 11:53
The commands are independent of map type, it'll handle it for you.

First thing is you have to call the _TMX_Init subroutine to initialize UDTs and other variables.

Command List:
tmx_LoadMap(filename)
tmx_FreeMap()
tmx_DrawMap(TMX_Map, offsetX, offsetY)
tmx_DrawGridTile(TMX_Map, pixelX, pixelY)
tmx_DrawGrid(TMX_Map, offsetX, offsetY)
tmx_GetTileAtPixel(pixelX, pixelY, offsetX, offsetY)
tmx_getPixelAtTile(tileX, tileY, offsetX, offsetY)


After calling getTileAtPixel or getPixelAtTile, the coordinates are stored in the global variable TMX_Mouse. See the code comments for further details.


So here it is. Enjoy!


Hold right mouse button to drag map around the screen.
Press 'G' to toggle grid.
Press 1-3 to switch between different maps
Press space key to end the demo.


Here's the main source file for the demo. The bulk of the code doing all the real work is broken down into two other files.


"You're all wrong. You're all idiots." ~Fluffy Rabbit

Attachments

Login to view attachments
tokyomage
13
Years of Service
User Offline
Joined: 26th Sep 2010
Location: on your roof
Posted: 2nd May 2013 21:35
Cool


Did you know that water is wet? - "The more you know"
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd May 2013 06:32
I did some benchmarking. These example maps are very small and load almost instantly.

Orthogonal: 280ms
Isometric: 142ms
Staggered: 56ms

I built the overworld map from legend of zelda, which is 256x88 tiles, and I have to say a real map size took quite a bit longer to load.

Zelda: 26,677ms

The load times also reflect the time to load the image tilesets and parsing them into individual tiles, but those load very quickly and are parsed from a memblock. My zelda TMX map was over 45k lines long which took nearly half a minute to fully load. If some assumptions are made about the format structure, it could probably be sped up.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Scotty1973
AGK Backer
12
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 13th May 2013 01:02
Hi

Tried it out and it works great!!

Still doing some testing but it is a great help!

Thanks

Scotty1973
Duffer
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: chair
Posted: 18th May 2013 11:43
This could be useful - thanks!

a long time dabbler with DBC and DBPro with no actual talent but lots of enthusiasm...
Scotty1973
AGK Backer
12
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 18th May 2013 17:30
Hi Phaelax

After some testing I have found 1 slight problem,
If you load a tile in that is much larger than the map tile size it will paste the image a lot lower than it should be.

To counter this when you paste the tile, on the Y axis you need

(ty+oy) - IMAGE HEIGHT(TMX_Map(x,y,i).gid ) + Map.TileHeight

This is on the Orthogonal format as that is the one I was trying.

I did this with my program, that I have been developing and it works better for paste image positioning. It wont matter if tile size is same size as map tile size.


Scotty
Duffer
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: chair
Posted: 18th May 2013 17:52
@ Phaelax,

Could you write a version to work with DBPro?

a long time dabbler with DBC and DBPro with no actual talent but lots of enthusiasm...
Scotty1973
AGK Backer
12
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 19th May 2013 08:22
@Duffer

This does work with dark basic pro

Scotty

Login to post a reply

Server time is: 2024-03-29 09:21:10
Your offset time is: 2024-03-29 09:21:10