Using tiled with SDL2

Hi !
I’m new to Tiled (and quite to English so excuse me for the mistakes I can make) and I would like to program a game with SDL2 using the TMX format. Therefore I installed libtmx by jube. But I have few problems to use it :
How can I use the visitor with SDL? I need a renderer to render tile but the function visitTileLayer(const tmx::Map& map, const tmx::TileLayer& layer) has no renderer. Moreover, I’d rather get all the informations than be forced to use them in the visitor. How can I do that?

Did you read the documentation of the library? Here it explains how you could implement the rendering, though you’d need to fill in the SDL2 part yourself:

http://jube.github.io/libtmx/tile_rendering.html

I think in general the visitor pattern is quite nice since it avoids having to manually deal with determining the type of each layer and casting it. However, if you don’t want to use it then you could just iterate the result of getLayers rather than calling visitLayers on the tmx::Map class:

http://jube.github.io/libtmx/classtmx_1_1_map.html

Btw, given that SDL 2 is a C library I wonder if maybe you’d be more comfortable using it with the tmx library by Bayle. It features an Allegro 5 example and an SDL 2 example.

Thank you. I’m going to try the library by Bayle. I didn’t see the SDL example (shame on me)…

So I’m trying to use tmx by Bayle . I installed jansson by compiling the source without error and I also installed tmx but I get an error when I try to compile :

/usr/bin/ld: ./lib/libtmx.a(tmx_json.c.o): undefined reference «json_object_iter_next»
//lib/x86_64-linux-gnu/libjson-c.so.2: error adding symbols: DSO missing from command line

Do you know how to fix it?

[Edit] I’ve spent my afternoon on this but I solved it… Didn’t know that the order in g++ was important, that seems to be new. So , for those who have the same problem, here are my compiler’s options (its important to add libtmx first):
/usr/local/lib/libtmx.a -ljansson -lz -lxml2

[Edit2] I’ve test (rapidly) the library and I’m satisfied : problem solved. Thank you very much.

Nice, thanks for letting us know the solution to your issue and that the library works well for you!