How to include assets in build


#1

I get asset for player straightforwardly like so:

SDL_Surface* temp_surface = IMG_Load("assets/player.png");

Naturally, the player will only load if player.png exists, in a folder called assets that also has to exist inside the project directory.
When the program is build, this remains the case. Assets has to be there, sitting next to the .dlls and the .exe. This is very sub-optimal. I would not like for a casual user (one without the means and intention to data-mine) to see the assets of my project (what if it’s a story driven game? That would be spoilers!)

Unsure if this is an SDL problem per se, but I’m putting it in the SDL Dev category just in case there’s something about this in the SDL documentation that I missed.

I’m using Code::Blocks v17.12.
I am writing the game in C. I will switch to C++ if that would lead to the only feasible means of solving this issue.
I am very early in development (which is to say, I haven’t started actually developing anything.) I am just scoping out my environment and my tools, and so am willing to be very flexible and adaptive in order to get something to build properly.


#2

You could put the assets in some kind of archive and load the game data from there.
The simplest solution might be a .zip archive (maybe with a different filename if you want to confuse the less clever of your players).
https://www.icculus.org/physfs/ can help accessing the files in zips or also from the FS in a unified way and can be integrated with SDL and its helper libs with SDL_RWops (see https://wiki.libsdl.org/CategoryIO)
(PhysFS doesn’t only support zip but also other kind of archives, see its homepage)


#3

So all a user would have to do is notice the .zip folder and then unzip it in order to see the assets?


#4

You could convert your files to binary and include them in your project as a file.

Stopping ppl from stealing your assets is a lost cause. Ppl will rip, extract, datamine your assets if they really want them.


#5

In my game engine I have embebed asset in the library with https://github.com/gwilymk/bin2c that convert a binary file to a C array. Then I make a SDL_RWops with SDL_RWFromConstMem(arrayname, arrayname_length) to use it.

I use PhysFS too for archives loading. You can make a Zip with a password, but the password will be in “clear” in your code, but you could use technique to obfuscurate it.

And I combine the bin2c and physfs for embedding archives too.

Keep in mind that even for big game compagnies the asset can be acceded (for example the Blizzard’s one are easily extracted.