Change Ressource path

Change Ressource path
0.0 0



I am completely new to cocos2dx, and maybe be question is really stupid, so please be kind :slight_smile:

It seems to be, at least when using the HelloCpp sample as a basis for a new project, that the path to the
Resource files is somehow hard corded, beeing something like “…/…/…/Resources”

How can I change this? I would like to be able to specify the path the the Resource directory.



What platform are you using?
I’m not sure how on Android/Eclipse but on XCode, you can just change where the Resources folder points to in the right-side pane.


Hi Lance Gray,

I am developing under Linux using Eclipse.

Using Linux as a developer platform is fully supported I hope ?



I’m not sure about Linux, but I can compile using Eclipse on my Mac OS X. I’m just not sure how to change the Resources folder. However, I believe it has something to do with and jni/


Hi Manuel!

I think, that in version 2.1.1 you have the following opportunities…

  1. You can change the default resource path at CCFileUtils::init.
  2. You leave the init implementation of CCFileUtils untouched and pass an absolute path of your desired resource directory toCCFileUtils::setSearchPaths.
  3. You derive your own class from CCFileUtils and initialize the attributem_strDefaultResRootPath with the absolute path to your app binary.
    Then you can use _CCFileUtils::setSearchPaths(const std::vectorstd::string&)_ to pass a relative path, like “…/Resources” or anything else relative to the binary of your app.

I have used the second method already successfully.



Hola Miro,

I dont want to extend or change the framework, so I tried you second suggestion (i.e adding a search path )
but it is till not working out for me.

I wanted to specify a resource path to be “./Resources” but when CCFileUtils::setSearchPaths(const std::vectorstd::string
is called with relative relative paths, they will be appended to the current m_strDefaultResRootPath.

Resulting in something like /gamedev/Test/…/…/…/Resources/./Resources/picture.png

I will just stick to the fix, creating a output directory that is three layers deep.

Thank you


Manuel, as already described, just create an absolute path and add to this your desired relative Resource directory. That’s what I did to overcome the missing possibility for pointing ‘m_strDefaultResRootPath’ to another directory.

For instance, create your own function that returns the absolute path to your app, like this:

std::string getAbsAppPath()
    char fullpath[1024] = {0};
    ssize_t length = readlink("/proc/self/exe", fullpath, sizeof(fullpath)-1);
    fullpath[length] = '\0';

    std::string appPath = fullpath;

    return appPath;

Or pass to this function your relative resource directory, concatenate the strings already within the function and return the final path. Or return an vector containg the full path. - However you like :wink:
Then, just feed CCFileUtils::setSearchPaths(…) with your self created absolute path to get the desired behaviour.



Hi Miro,

you are right, I assumed a absolute path to be static as well, but as you showed one can create it dynamically during

I just wonder to put this code, as it is platform specific and I dont want to mix it with the platform independed code.



Actually, the game developer should not be forced to write platform dependent code, it should be hidden by the framework.
In our case, I think the framework needs some improvements, because we are just introducing a workaround into our own applications to overcome a weakness of the API.

However, you can extend your code for other targets and select the appropriate solution during compile time with preprocessor statements.

    // My Linux specific readlink solution
    // My Windows specific GetCurrentDirectoryW solution
#error other platforms then LINUX and WINDOWS are currently not supported

Good Luck!