How to use xmlparser to load tmx maps?

Started by
4 comments, last by georger.araujo 8 years, 10 months ago

Apparently its very easy to do this which makes this pretty discouraging, but I'm just plain confused.

I'm making a Platformer with SFML/Box2D and c++ and want to know how I can use xmlparser to load a tmx map from Tiled. Whats confusing me more than actually using tmxparser code is linking it to my project.

How do I get xmlparser to actually work with my project? Can someone give me a step by step guideline?

Also, after I do get xmlparser working and I actually get a tmx map on the screen, how do I use Box2D so that the tiles that have collision actually collide with my character?

Advertisement

tmxparser contributor here.

Take a look at test/test.cpp in the source tree -- you'll see that it is easy to parse your .TMX, but tmxparser's job is finished after the file has been parsed. Everything else (including rendering and collision detection) is up to you.

Perhaps you should take a look at sfml-tmxloader? It integrates SFML and .TMX parsing, and has a Box2D example. Haven't used it myself, though.

Ok thanks for those links. The thing is I'm having trouble actually linking it to my project. I doubt I just put the files with my project and do a #include. Am I wrong in saying that?

Ok thanks for those links. The thing is I'm having trouble actually linking it to my project. I doubt I just put the files with my project and do a #include. Am I wrong in saying that?

Since tmxparser is not a header-only library, the approach you just described would not work.

Building and using tmxparser is very much like building and using any other library that uses CMake as its build system. Also, you need working installations of zlib and TinyXML.

- Build and install the library with CMake;

- #include the appropriate header files (test/test.cpp is a good starting point) in your code;

- Link your project against the appropriate import library that was built in step #1;

- Profit.

sfml-tmxloader also uses CMake, and has an examples folder in the source tree. So it should be trivial to build it and link it to your project.

And if you're having trouble with these instructions, well, it's something you just have to live with when developing with C++: you have to learn the language AND understand the compilation process AND have a working knowledge of build systems, since not all libraries offer binary downloads.

Ok thanks for those links. The thing is I'm having trouble actually linking it to my project. I doubt I just put the files with my project and do a #include. Am I wrong in saying that?

Since tmxparser is not a header-only library, the approach you just described would not work.

Building and using tmxparser is very much like building and using any other library that uses CMake as its build system. Also, you need working installations of zlib and TinyXML.

- Build and install the library with CMake;

- #include the appropriate header files (test/test.cpp is a good starting point) in your code;

- Link your project against the appropriate import library that was built in step #1;

- Profit.

sfml-tmxloader also uses CMake, and has an examples folder in the source tree. So it should be trivial to build it and link it to your project.

And if you're having trouble with these instructions, well, it's something you just have to live with when developing with C++: you have to learn the language AND understand the compilation process AND have a working knowledge of build systems, since not all libraries offer binary downloads.

Then before I go into my game I'm going to learn all this. Thanks a lot.


Then before I go into my game I'm going to learn all this. Thanks a lot.

I recommend chapters 2 and 11 of An Introduction to GCC, and the official CMake Tutorial. These are, of course, "must-know" rather than comprehensive.

This topic is closed to new replies.

Advertisement