转自:http://blog.csdn.net/ruanyubiao/article/details/25890997
今天遇到了资源找不到的问题,看了代码,了解了下cocos2d的资源搜索方式
新建一个项目,我的路径F:/projects/luatest/
CCFileUtils::getInstance()->addSearchPath("F:/projects/luatest2"); CCFileUtils::getInstance()->addSearchPath("src"); /* 此时 searchPath 有3个 1. "F:/projects/luatest/" 默认项目路径 2. "F:/projects/luatest2" 3. "F:/projects/luatest/src/" */ CCFileUtils::getInstance()->addSearchResolutionsOrder("res"); /* resourceDirectory 有2个 1. "" 默认,空 2. "res/" */ //测试:寻找close.png,这个文件不存在,看看cocos2d搜索了哪些路径CCFileUtils::getInstance()->fullPathForFilename("Images/close.png"); /* cocos2d搜索的时候,会把文件名分拆成两部分,具体看CCFileUtils.cpp的FileUtils::getPathForFilename file_path = "Images/" filename ="close.png" */ /* //搜索路径组合方式: searchPath + file_path + resourceDirectory + filename 最终搜索的所有路径 F:/projects/luatest/Images/close.png F:/projects/luatest/Images/res/close.png F:/projects/luatest2/Images/close.png F:/projects/luatest2/Images/res/close.png F:/projects/luatest/src/Images/close.png F:/projects/luatest/src/Images/res/close.png */