2013-08-01 62 views

回答

0

创建文件夹“iphone”“iphone4”“iphone5”“ipad”“ipadhd” 此代码将智能加载来自不同文件夹的资源。就像在iphone5上,如果资源不存在,它将首先扫描“iphone5”文件夹。它将扫描“iphone4”文件夹中的视网膜资源,如果它不存在。它会扫描“iphone”文件夹。 因此,您的资源必须在不同文件夹中具有相同的文件名。

在AppDelegate.h添加托斯特的代码:在布尔的AppDelegate

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 ::的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); 
相关问题