Xcode4 使用应用程序自动获取cocos2dx的当前资源

Xcode4 使用应用程序自动获取cocos2dx的当前资源,xcode4,cocos2d-x,Xcode4,Cocos2d X,ipad、ipad视网膜、iphone、iphone4和iphone5的通用设置。创建文件夹“iphone”“iphone4”“iphone5”“ipad”“ipadhd” 此代码将智能加载来自不同文件夹的资源。就像在iphone5上一样,如果资源不存在,它将首先扫描“iphone5”文件夹。它将扫描“iphone4”文件夹中的视网膜资源,如果它不存在的话。它将扫描“iphone”文件夹。 因此,您的资源必须在不同的文件夹中具有相同的文件名 在AppDelegate.h中添加以下代码: type

ipad、ipad视网膜、iphone、iphone4和iphone5的通用设置。

创建文件夹“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"};
在bool Appdelegate::applicationdFinishLaunching()函数的Appdelegate.h中:

/////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);
///retina
资源resDevice[5]={resIphone5,resIphone4,resIphone,resIpad3,resIpad};
CCEGLView*pEGLView=CCEGLView::SharedPenglView();
CCSize frameSize=pEGLView->getFrameSize();
资源resActual=resIphone;
std::向量响应路径;
for(int i=0;isetContentScaleFactor(resActual.sizeInPixel.width/resActual.sizeDesign.width);
pEGLView->setDesignResolutionSize(resActual.sizeDesign.width、resActual.sizeDesign.height、kresolutionNoOrder);