Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

closed as not constructive by Nicol Bolas, Josh Petrie, 21st Century Moose, Trevor Powell, Ali.S Dec 9 '12 at 6:56

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

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. – Benjamin Danger Johnson Oct 23 '12 at 23:49
up vote 4 down vote accepted

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.

share|improve this answer
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 :) – Bugster Oct 23 '12 at 19:43
By the way: all the XML::* helper functions which are used all over that code are implemented here: – Philipp Oct 23 '12 at 19:48
Thanks a bunch. – Bugster Oct 23 '12 at 19:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.