Multi resolution for iOS and Android

Multi resolution for iOS and Android
0.0 0



I am struggling with setting the multi resolution for both iOS and Android. I created the textures my application using 1024x768 resolution as a reference. I used TexturePacker to generate the HDR, HD and SD files. I am using Cocos2d-X version 2.2.1

My problem is that I cannot manage to configure the application properly. The code that I am using is this

`CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
CCFileUtils *pFileUtils = CCFileUtils::sharedFileUtils();
std::vectorstd::string searchPaths;

CCSize designSize = CCSize(1024, 768);

CCSize resourceSize;
// if the device is iPad
if (screenSize.height >= 768)

    resourceSize = CCSizeMake(1024, 768);
    designSize = CCSizeMake(1024, 768);
// if the device is iPhone
    // for retina iPhone
    if (screenSize.height > 320)
        resourceSize = CCSizeMake(960, 640);
        resourceSize = CCSizeMake(480, 320);

pDirector->setContentScaleFactor(resourceSize.width / designSize.width);

CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionFixedWidth);`

I also tried to follow some tutorials such as this and this, but so far I am not able to make the stuff working.

Does anyone knows what should I do to support multi resolution for both iOS and Android?

Thanks a lot in advance


My english is really bad, so let’s code speak. First of all, some constants will help:

typedef struct tagResource {
    cocos2d::CCSize size;
    char directory[100];
} Resource;

static Resource smallResource = { cocos2d::CCSizeMake(480, 320), "SD" };
static Resource mediumResource = { cocos2d::CCSizeMake(960, 640), "HD" };
static Resource largeResource = { cocos2d::CCSizeMake(1024, 768), "HDR" };

static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(1024, 768);

Now in applicationDidFinishLaunching(), you can proceed as follow:

CCSize frameSize = pEGLView->getFrameSize();
// Set the design resolution
pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionFixedWidth);

std::vector<std::string> searchPaths;
if (frameSize.height <= smallResource.size.height) {
} else if (frameSize.height <= mediumResource.size.height) {
} else{



Thanks a lot for your answer. I tried your code but it does not work. Honestly, I don’t get it. If you compare my code with your code it is exactly the same stuff.

I am also sure that I configure correctly TexturePacker. I selected the Data Format as cocos2d, and in the Auto SD I selected cocos2d-x HDR/HD/SD.

This issue is driving me crazy, since I am following exactly the same code as everyone is using :;fury

Does anyone else has the issue as I do?

Thanks a lot


Do you have your SD and HD directories in the right location on your file system, etc.

Example, on OS X I have to have an SD and HD directory in my Resources/ directory.


Yes, I have the directories under Resources.
For the moment, I plan to do

CCSize designSize = CCSize(1024, 768);
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionFixedWidth);

And use only one texture for all the resolution.

I know it is not the most elegant solution, but it works. I will keep digging with this issue on v3.0


Make your self a coffee .
and read this document also , its less known one in the Cocos2d-x documentations

also please
Take a look at the HelloCpp example , Specially the AppMacros.h file , there is info in the comments there .

also if you read about the term Playable rectangle ( visible area )
take a look at the files VisibleRect.h/cpp in the TestCpp tree .
please remember there is no perfect solution to screen fragmentation you will have to hack
something in between


Thanks a lot, I will have a look