问题
I met the problem I cannot create CCSprite in cocos2d-x Android.
I have a xml file which store the file path. And I read the file path to create a Sprite. The Sprite is NULL.
CCSprite* pSprite1 = CCSprite::create(tempfilename.c_str());
tempfilename contains withword\\stone_0.png
.All my resources is located under assets\..
,and this png is located under assets\withword\stone_0.png
. I don't know why I cannot create this sprite. How can I solve this problem?
I have checked this topic but still don't know.
回答1:
You have to add sub directories to your search path in cocos-2dx,
You can do this in your AppDelegate::applicationDidFinishLaunching()
method before loading any scene.
int i = 0;
CCFileUtils *fileUtils = CCFileUtils::sharedFileUtils();
std::vector<std::string> searchPaths = fileUtils->getSearchPaths();
searchPaths.insert(searchPaths.begin() + i++, "withword");
fileUtils->setSearchPaths(searchPaths);
来源:https://stackoverflow.com/questions/23007035/cannot-create-ccsprite-with-subfolder-png-when-port-to-android-application-with