Resources: CCFileUtils setResourcePath or xcopy?


#1

I’m currently using

#ifdef WIN32
CCFileUtils::setResourcePath("./Resource/");
#endif

instead of xopy’ing my assets to the Debug.win32 directory every build. Is there a reason why I should not be doing this?

I also discovered that the default resource path location is not the current working directory of the executable but the directory where the executable/dll/module is located in.

Thanks,
ppl

If anyone else is looking for this… here it is:

// cocos2d-0.99.5-x-0.7.2-rc\cocos2dx\platform\win32\CCXFileUtils_win32.cpp

// [...]

void _CheckPath()
{
    if (! s_pszResourcePath[0])
    {
        WCHAR  wszPath[MAX_PATH];
        int nNum = WideCharToMultiByte(CP_ACP, 0, wszPath, 
            GetModuleFileName(NULL, wszPath, MAX_PATH), 
            s_pszResourcePath, MAX_PATH, NULL, NULL);

        for (int i = nNum; i >= 0; --i)
        {
            if (L'\\' == s_pszResourcePath[i])
            {
                s_pszResourcePath[i + 1] = 0;
                break;
            }
        }
    }
}

#2

CCFileUtils::setResourcePath is the runtime function, the ‘.’ means the path of the cocos2d-x application.
xcopy is the PostBuildEvent, the ‘.’ means the path of the cocos2d-x project file.

If you wan’t use setResourcePath, make sure the parameter path is correct, the related path relate application binary or the absolute path.


#3

Right, the relative path given to setResourcePath() is relative to the working directory of the project which, by default, is set to $(ProjectDir) with VC++2010.

You can change that option in the Configuration Properties of the project in “Debugging>Working Directory.”