I'm programming a little game in SDL and the files are structured like this:
"src/game/" have both .h and .cpp source files.
"data/" have the game files like maps, tilesets, sprites and so on...
to load a sprite for example I would use the following code.
spriteLib.loadSprite("data/sprites/sprite-ghost.bmp");
to convert this string to an absolute path I have those lines in the first 4 lines of the function:
SSprite CSpriteLib::loadSprite(std::string file)
{
//Converting the file path
char converted[128];
realpath(file.c_str(),converted);
file = converted;
But this way the program only compiles under liux so... if anyone knows another way to do that I would be grateful.
Boost is your friend. Here's a link to the Boost Filesystem tutorial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With