Can I create relative filepaths to images in an XCode SDL project?
I have to use absolute filepaths as it is, but it would be much easier if I could make the filepaths relative.
Can I create relative filepaths to images in an XCode SDL project?
I have to use absolute filepaths as it is, but it would be much easier if I could make the filepaths relative.
Changing the working directory worked for me recently:
Go to Product -> Scheme -> Edit Scheme.
Then click Run on the left hand panel and then finally enter the path of the files under Working Directory.
All of your paths are then relative to the path you entered.
you could place your files in a folder called resources or whatever you want it to be at the same directory as the exe. For the file path when using a SDL_LoadBMP() or whatnot will be resources/name_of_image.bmp
XCode usually runs your project from an internal directory used for development. One easy way to get the path to your program is to query NSBundle.
NSString * filename = @"images/my_image.jpg";
NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
NSString * fullPath = [filename stringByAppendingPathComponent:filePath];
// fullPath is now the absolute path to the file.
You didn't specify the language, but if you are using C++, you can still use Objective-C inside a .mm file, in the same project.