3
\$\begingroup\$

I have attempted to use Tiled for creating 2d maps, and saving them under a text file. The resulting text file seems difficult to parse at first, I gave it a shot here however to no good result.

I have been wondering if anyone has a basic tiled map parsing algorithm. I have searched for a possible algorithm but to no avail so far.

\$\endgroup\$
1
  • \$\begingroup\$ You can probably write your own export format, you just need to make the first set number of file bytes store your width/height and then store byte codes for each tile type (grass = 0x01, water = 0x02, etc.) It's a bit more difficult, but I prefer to do things in a way that give me complete control over them. \$\endgroup\$ Oct 23, 2012 at 23:49

1 Answer 1

4
\$\begingroup\$

Note that the txt export option of Tiled is a format used by one specific engine. Copying that format might not be the best solution for your use-case.

I would recommend you to save your Tiled maps in the native TMX format and parse it with an XML parser like libXML. The JSON export is also an option, but I have never worked with any JSON library in C++, so I can't recommend you one.

Open source code which loads TMX maps with libXML2 can be found in the sourcecode of the client of the open source MMORPG The Mana World. By the way: The lead developer of Tiled is also participating in the development of TMW.

Full Disclosure: I used to be a developer of TMW myself and wrote a few lines of the code linked above.

\$\endgroup\$
2
  • \$\begingroup\$ That's an excellent example. I didn't think of XML parsing yet as it seems game developers tend to avoid it. If no more answers will come up I will also accept the question :) \$\endgroup\$
    – Bugster
    Oct 23, 2012 at 19:43
  • \$\begingroup\$ By the way: all the XML::* helper functions which are used all over that code are implemented here: github.com/mana/mana/blob/master/src/utils/xml.cpp \$\endgroup\$
    – Philipp
    Oct 23, 2012 at 19:48

Not the answer you're looking for? Browse other questions tagged .