cocos2dx 2.0后不再支持-hd这种方式来启用高清图片,而是变为需要在CCFileUtils中指定图片的目录来启用,本例中文件结构如图所示,Misc目录位于Resources下,注意文件夹是蓝色的(按文件夹引用非按组引用),然后按下面的代码配置路径。如要支持iPad,配置方法基本相同
方法一:(这种方法需要准备多套图片,如果要同时支持ios和android,这种方法不太可行)
CCFileUtils *sharedFileUtils = CCFileUtils::sharedFileUtils();
sharedFileUtils->purgeCachedEntries();
std::vector<std::string> searchPaths = sharedFileUtils->getSearchPaths();;
searchPaths.insert(searchPaths.begin(), "Misc");
sharedFileUtils->setSearchPaths(searchPaths);
std::vector<std::string> resolutionsOrder = sharedFileUtils->getSearchResolutionsOrder();
resolutionsOrder.insert(resolutionsOrder.begin(), "res-hd");
resolutionsOrder.insert(resolutionsOrder.begin()+1,"res");
sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("fruit_sheet.plist");
CCSprite *fruit = CCSprite::createWithSpriteFrameName("fruit0");
fruit->setPosition(ccp(200,200));
addChild(fruit);
方法二:(这种方法只需要一套图片,一般只要准备最高分辨的那套图,通过设置DesignResolutionSize让cocos2d自动缩放适应,推荐使用)
// Set the design resolution
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionExactFit)
例如要用一套图支持480x320和960x640两种分辨率,那么designResolutionSize定义如下
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(960, 640);
关于DesignResolutionSize可以参考这篇博文http://www.kaifazhe.com/mobile/311125.html