2013-08-01 61 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); 
相關問題