适用于 ipad、ipad 视网膜、iphone、iphone4 和 iphone5 的通用设置。
问问题
345 次
1 回答
0
创建文件夹“iphone”“iphone4”“iphone5”“ipad”“ipadhd”此代码将智能加载来自不同文件夹的资源。就像在 iphone5 上一样,如果资源不存在,它将首先扫描“iphone5”文件夹。如果视网膜资源不存在,它将扫描“iphone4”文件夹以查找视网膜资源。它将扫描“iphone”文件夹。因此,您的资源必须在不同文件夹中具有相同的文件名。
在 AppDelegate.h 添加主机代码:
typedef struct tagResource{
CCSize sizeInPixel;
CCSize sizeDesign;
char directory[64];
}Resource;
static Resource resIphone={CCSizeMake(320, 480),CCSizeMake(320, 480),"iphone"};
static Resource resIphone4={CCSizeMake(640, 960),CCSizeMake(320, 480),"iphone4"};
static Resource resIphone5={CCSizeMake(640, 1136),CCSizeMake(320, 568),"iphone5"};
static Resource resIpad={CCSizeMake(768, 1024),CCSizeMake(768, 1024),"ipad"};
static Resource resIpad3={CCSizeMake(1536, 2048),CCSizeMake(768, 1024),"ipadhd"};
在 Appdelegate.h 中的 bool AppDelegate::applicationDidFinishLaunching() 函数中:
/////retina
Resource resDevice[5]={resIphone5,resIphone4,resIphone,resIpad3,resIpad};
CCEGLView* pEGLView=CCEGLView::sharedOpenGLView();
CCSize frameSize=pEGLView->getFrameSize();
Resource resActual=resIphone;
std::vector<std::string> resPaths;
for (int i=0; i<5; i++) {
if (frameSize.equals(resDevice[i].sizeInPixel)) {
resActual=resDevice[i];
}
float scaleBitPortrait=(float)frameSize.height/resDevice[i].sizeInPixel.height;
float scaleBitLandscape=(float)frameSize.width/resDevice[i].sizeInPixel.height;
CCLog("[res path] loop for: %s %f or %f",resDevice[i].directory,scaleBitPortrait,scaleBitLandscape);
if (scaleBitPortrait==1 || scaleBitPortrait==2 || scaleBitLandscape==1 || scaleBitLandscape==2) {
resPaths.push_back(resDevice[i].directory);
}
}
for (int i=0; i<resPaths.size(); i++) {
CCLog("[res path] load: %s",resPaths[i].c_str());
}
CCFileUtils::sharedFileUtils()->setSearchPaths(resPaths);
pDirector->setContentScaleFactor(resActual.sizeInPixel.width/resActual.sizeDesign.width);
pEGLView->setDesignResolutionSize(resActual.sizeDesign.width, resActual.sizeDesign.height, kResolutionNoBorder);
于 2013-08-01T03:34:33.763 回答