Resources Path

Hi,
I have created a project in android and Im porting it to windows phone 8, but I have run into problems.
In android, this works fine.

@ std::string Seperator = “”;
std::string startPath = “data”Seperator“levelData.xml”;
pugi::xml_document* doc = GetXML_Document(startPath.c_str());
pugi::xml_node mainNode = doc~~>child;@
but in windows phone 8,
I have to do it like this,
@ std::string Seperator = “”;
std::string startPath = “levelData.xml”;
pugi::xml_document* doc = GetXML_Document);
pugi::xml_node mainNode = doc~~>child(“main”);@

How do i get the same resource path working in windows 8? It will be too much effort if I have to change the path every where in my code.
Thanks.

You need to map all sub-directories in Resources folder to search path. Check out FileUtils demo in TestCpp project.

Also you can refer my answer on StackOverflow:
http://stackoverflow.com/a/20469359/457982

The issue is that, I have to change all my code. My file (if i go through windows explorer) is …/Resources/data/levelData.xml. Hence when I accessed it, I used the code above. I am on cocos2d-x 2.2.0 and it uses the same classes for all projects. Now in windows phone, even though the file is still located there(…/Resources/data/levelData.xml) I cannot access it using the same path (I get NULL when I try to load the file). I can access it by just its name. The issue is, I will have to change my whole code to this. Is there any other way to do this?

No you don’t need to change all code. You can add all sub-directories to search path vector in FileUtils.

You can do this in your AppDelegate::applicationDidFinishLaunching() method. Suppose You have 3 sub folders images, sounds and levels inside your Resources folder then you can add all of them to your search path using sample code like this :

    int i = 0;
    CCFileUtils *fileUtils = CCFileUtils::sharedFileUtils();
    std::vector searchPaths = fileUtils->getSearchPaths(); 
    searchPaths.insert(searchPaths.begin() + i++, "images");
    searchPaths.insert(searchPaths.begin() + i++, "sounds");
    searchPaths.insert(searchPaths.begin() + i++, "levels");
    fileUtils->setSearchPaths(searchPaths);

Now if you want to load any file inside Resources/images folder then you can just try:

CCSprite* pSprite = CCSprite::create("image.png")

Thanks.
How do I add sub-folders?

hi there I have another problem with windows phone

when I build the app and launch it, everything is fine but if I build it again and try launching it, the resources cant be found.

then if I clean the project > build> launch, works again

I’m quite new to visual studio, has anyone had something like this before?

Sorry for the late reply. I have not encountered anything like this.
I am having an issue with blackberry now.I have done this in the App Delegate

@ CCFileUtils *fileUtils = CCFileUtils::sharedFileUtils();
fileUtils~~>addSearchPath;
fileUtils~~>addSearchPath(“data”);
std::string filePath = “images” + Seperator + “logo”;
fileUtils->addSearchPath(filePath.c_str());@

And the images load correctly in the start. But after say 1 minute, if I try to access any image, it crashes cause it cant find the image. Just before loading the image, if I add the search path again, it works. Any idea why I have to keep doing this?

You might be clearing search path vector somewhere else in your program, otherwise it should work correctly.