Cannot create CCSprite with subfolder png when port to Android application with cocos2d-x?

拈花ヽ惹草 提交于 2019-12-25 07:27:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!