Tileson - A Tiled json parser for Modern C++

Forgot to mention: To compile the examples, the CMake flag BUILD_EXAMPLES must be activated. At this point I cannot guarantee that it compiles, as I’ve only tested the compilation on my working environment (Linux) for now.

Checked! Thanks for your example (it’s funny because your drawTileLayer class function is exactly the first modification I did on my previous code).

Once again: Thanks :slightly_smiling_face:

Thank you so much for posting that demo. I’m still looking at it. I’m on Windows, so I’ll see if I can get it going. Lol I hope you find the time to finish out this demo

Ok I fixed my nullptr exception, now I’m hung up on getting the demo-tileset to load. It keeps giving me an invalid path error

So I lied I’m getting the nullptr exception again here are the screenshots:

@Shadow001: You need to update to the newest version of Tileson: Release 1.0.1. It fixes an issue which probably is causing your crash :slight_smile:

Lol I thought I had the most recent version :sweat_smile:

I got your demo to work! Lol now I need to study it and understand what is going on inside the program. Thank you so, so much for helping me out with this. I really really hope you can find the time to finish this demo

Hey attached is one of my Tiled maps, well the JSON file of it. Could you look at it and tell me why it’s so different looking then the one in the demo?untitled2.json (105.8 KB)

@Shadow001: I can look at it after work tomorrow. Meanwhile you can see if you get any help from looking at the newest SFML example :slight_smile: I added drawing of image layers, and drawing of the object types of the type “object”. Not far away from having an example for drawing the whole map now, but sadly I have to call it a day. I’ll get back to you tomorrow night :slight_smile:

@Shadow001: I took a quick look at your map, and noticed that you data is base64 encoded. At this point this is not supported by Tileson, so the parser will not know what to do. You should be able to load the map if you go to map properties and change the Tile Layer Format to CSV. Also the Tile Render Order might affect how the tiles are drawn. The demo map uses “Left Down”, while you are using “Right Down”.

I now have a full example that draws all the parts of the demo map using SFML in my latest commit. Now got it building on Linux (GCC) and Windows (using MSVC). Should build on OS X as well, using the homebrew version of llvm, but I have yet to get that verified. I got an old mac lying around, but I won’t have the time to verify that it works today.

Thank you so much!!! Also thank you so much for all your help and patience!!!

@Shadow001 You’re welcome :slight_smile:

Hi again,

I have a question a little bit off topic:
As soon as I made my render function in a standard game loop, my framerate become too slow to be pleasent to see (8<framerate<20 FPS)

My question: is the idea of rendering all my map (not only the displayed part) is absurd (even for quite small maps (ie. 50x50))? or should I consider a new loop pattern?

50x50 isn’t big at all and should not cause problems. Are you sure you’re rendering the map in a performant way? For example, are you perhaps rendering each tile with its own draw call, instead of batching them into fewer draw calls? Are you perhaps generating the drawable object(s) from the data on every frame, instead of having your drawable(s) created once and reusing it?

(This is very off-topic for this forum though, so I’d recommend taking it to DMs or another forum, as this one doesn’t have an off-topic section.)


I am really a noob with c++ game development. I have to do this for school so…

How do I run your project? I passed my path to a tiled json file in the main.cpp.
tson::Map map = parser.parse(fs::path("./src/level/level1.json"));
I have already added a tiled json file in the project and the path is correct.
But keeps saying file not found. It seems to be ignoring the main.cpp

How can I run this project?

Hopefully this is not a stupid question.

Thanks in advance!

How did you make sure the path is correct? Note that you are passing a relative path, which the program will resolve as relative to its working directory. This may not be where you think it is (you can check using std::filesystem::current_path() to be sure).

Good luck with your assignment, sounds like fun!

Thank you for your reply :).
How can I run the main.cpp? The main.cpp is not being called. It only calls the tileson_tests.exe

Hmm, that depends on how the project is set up and your development environment. Maybe @SSBMTonberry can help with that. If this is a Visual Studio usage question, you may just need to activate a different project in the solution view.

But do you know how to install this in my project with cmake? I don’t find a guide for this.

@ffbodie: Sorry for the late reply. I have been very busy lately…
First of all I think @bjorn is right when he says that your path probably isn’t pointing to a file. “./” means the folder relative to the running executable, and unless you actually have created the folder “./src/level/” exactly where the .exe runs, it will not be valid. You can easily check if you have a valid path, by doing something like this:

fs::path path = fs::path("./src/level/level1.json");
bool pathExists = fs::exists(path);

Keep in mind that fs is an alias for std::filesystem that is used by Tileson.
If pathExists has the value true, then you are right, if not: then the path is not valid.
Since Tileson uses this functionality itself, I am fairly certain that the path you specified is not valid from where your .exe is running.

Sounds like you have recently started programming in C++. If this is the case, I would suggest you try making a regular C++ program using Visual Studio. Tileson uses CMake because it is designed to be cross-platform, but I would not recommend you to start there. Sounds like you have been able to build Tileson with its examples, which is a good start! When you built the project there is a Tileson.lib(default) or Tileson.dll file created (depending on how you configured CMake). You will need to use this when linking with your new Visual Studio project. You will also need all the header-files (*.h) related to Tileson for your project to recognize Tileson’s functions. You will need to read up on how you link libraries with Visual Studio, but it’s easy to find on the internet. Good luck! :slight_smile:

Additional note: .lib is libraries used for static linking (they will be built into your .exe), while .dll files are not built into your .exe, and will be required inside the same folder as where your .exe is for your program to work.

@ffbodie: Also: Check out SFML if you want to make a 2D game (handles drawing, input, sound, networking etc.). If you go to their home page they have very good tutorials how you use their library, and how you link SFML using Visual Studio.