Advertisement

SFML and Tiled Map Editor

Started by November 03, 2013 03:20 AM
3 comments, last by Servant of the Lord 11 years ago

So I'm using sfml and to make the map I'm using the Tiled map editor. I found this to parse the data for sfml but the problem is I'm not sure I understand how to get it as part of the project.

http://trederia.blogspot.co.uk/2013/05/tiled-map-loader-for-sfml.html

I asked how to add this to my project and the author of the blog post put this.

put the header files in a directory which is in your projects include path, and add the cpp files to your project. You'll also need zlib which you download then add in the same way as SFML

There are a lot of cpp files in various folders and the zlib structure isn't the same as sfml so I don't know where it's include, lib, or what additional dependencies to put down.

Sorry if this is a stupid question.

When you have a project: Your project has .cpp files and .h files. Your project also links to .dll files and .a files and #includes .h files of other projects / libraries.

Do you already have your project up and running and compiling already and already using SFML, without being able to load maps? If not, that's step one before you try loading maps.

This part of C++, where you get other projects to interact with your own, can be confusing and take alot of patience and trial-and-error, so no, it's not a stupid question, but it can be a hassle you'll have to fight through by perseverance. Every project I want my code to work with is slightly different, and figuring out how to compile them or make them play nice with my code is always a little bit of a hassle. You can download precompiled versions... but those can be hassles also, for a dozen different reasons.

Because of this, you cannot be given a three, five, or even ten-step tutorial that will universally work. It'd be more like a giant flowchart of "Is your project X? Are you trying to use Y? Are you compiling with Z? Do you have Q enabled? Does the library also have Q enabled? Do you want to use it as N or as M? Did the project..." and so on. It always takes trail and error, and ain't fun, but you'll get used to it eventually.

Sorry for not being able to give you a pleasant answer! ohmy.png It's my least-favorite part of programming.

But programming in general is fun, so don't get discouraged by the unfun parts! smile.png

Also, this specific bit of hassle becomes less of a pain once you become familiar with how to work through the problems as they arise.

Probably the easiest option, in this one specific case, for this one specific circumstance, is to copy the library's .cpp files that are in the 'src' folder (only the ones in the 'src' folder, not the .cpp files outside of it), into your own project's .cpp files, and copy the project's .h files that are in the 'include' folder and paste those with your own .h files, and then tell your specific IDE, in whatever specific way your IDE does it, to count those .cpp files and those .h files as part of your project.

That's part A, which may have all kinds of compile issues and stuff that you'll need to work through in a manner completely unique to your specific situation.

Part B would be linking to zlib, which is a different set of ifs, whens, and maybes, and a different set of potential compiler errors and unique setup that differs from person to person.

So I guess back to the first question: Does your project already compile fine and run fine using just SFML, without loading maps? smile.png

Advertisement

Copying all files of all libraries into a single directory of your project may be the easy way out, but also the wrong way. Later you will see the created mess and not know from where you got which file from and then good luck if you try to update one of the libraries. Better learn from start how to compile each library separately and set up project files or make files to make the compiler/linker search the header/library files inside all of the needed directories.

Why dont you read the tutorials, its all explained there for SFML?

When you know that its really easy to do the same and set up zlib, there are also instructions included.

I got SFML to linked and compiled. I noticed I downloaded the wrong zlib, I didn't get the dll but I do now. For zlib that sounds too easy. Isn't there supposed to be additional dependencies in the Project > Properties > Linker > Input > additional dependencies. Like sfml had the sfml-graphics.lib files I had to add.

I'm not really looking for the easiest way. Probably somewhere between cleanest setup and easy. The way Servant of the Lord described setting it up sounds messy. I was hoping for a process similar to setting up SFML where the only files I need to move around are dll or something.

It works for small libraries, and is only messy if you let your normal code files get messy. Some code libraries are only distributed as just a two or three source files are were never intended to be compiled into DLLs. I definitely don't advocate using every project directly, just the ones that are small enough and make sense to do so - I downloaded and skimmed through the code in question before posting.

This is actually the suggested way that the author of the library mentioned when you asked him:

"put the header files in a directory which is in your projects include path, and add the cpp files to your project."

It's only as messy as the rest of your project is messy. If you keep your own code organized, then adding new projects won't make it unorganized. Putting the code in a subfolder would be a good start to maintaining organization.

Yes, it definitely could be compiled as a DLL, but it doesn't need to be. But if you want to compile it as a self-contained library anyway, then I'd suggest a static library over a DLL - it'd avoid some unnecessary hurdles that wouldn't gain you anything (in this specific situation). That's my unprofessional opinion, anyway!

This topic is closed to new replies.

Advertisement