I am completely new to cocos2dx, and maybe be question is really stupid, so please be kind
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.
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 build_native.sh and jni/Android.mk
I think, that in version 2.1.1 you have the following opportunities…
You can change the default resource path at CCFileUtils::init.
You leave the init implementation of CCFileUtils untouched and pass an absolute path of your desired resource directory toCCFileUtils::setSearchPaths.
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.
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.
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:
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
Then, just feed CCFileUtils::setSearchPaths(…) with your self created absolute path to get the desired behaviour.
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.
#if LINUX
// My Linux specific readlink solution
#elif WINDOWS
// My Windows specific GetCurrentDirectoryW solution
#else
#error other platforms then LINUX and WINDOWS are currently not supported
#endif