Support retina in 2.0.4

(iPhone 5 resolution support was added)
Realisation of enableRetinaDisplay in cocos2d-x version 2.0.4
A more complete solution than in the documentation.

In AppDelegate.cpp add this:

typedef struct tagResource
{
    CCSize sizeInPixel;
    CCSize sizeDesign;
    char directory[100];
}Resource;

static Resource resPhone  =  { CCSizeMake(480, 320), CCSizeMake(480, 320), "iphone" };
static Resource resPhoneRetina35 =  { CCSizeMake(960, 640), CCSizeMake(480, 320), "ipad" };
static Resource resPhoneRetina40 =  { CCSizeMake(1136, 640), CCSizeMake(568, 320), "ipad" };
static Resource resTable =  { CCSizeMake(1024, 768), CCSizeMake(1024, 768), "ipad" };
static Resource resTableRetina  =  { CCSizeMake(2048, 1536), CCSizeMake(1024, 768), "ipadhd" };

and this:

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

    ///////////////////////////// retina support solution start
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
    CCSize frameSize = pEGLView->getFrameSize();
    Resource actualResource;
    float actualWidth = max(frameSize.width, frameSize.height);
    if (actualWidth > resPhoneRetina40.sizeInPixel.width) {
        actualResource = resTableRetina;
    } else if (actualWidth > resTable.sizeInPixel.width) {
        actualResource = resPhoneRetina40;
    } else if (actualWidth > resPhoneRetina35.sizeInPixel.width) {
        actualResource = resTable;
    } else if (actualWidth > resPhone.sizeInPixel.width) {
        actualResource = resPhoneRetina35;
    } else {
        actualResource = resPhone;
    }
    //CCFileUtils::sharedFileUtils()->setResourceDirectory(actualResource.directory);
    pDirector->setContentScaleFactor(actualResource.sizeInPixel.height / actualResource.sizeDesign.height);
    // Set the design resolution
    pEGLView->setDesignResolutionSize(actualResource.sizeDesign.width, actualResource.sizeDesign.height, kResolutionNoBorder);
    ///////////////////////////// retina support solution end

Much appreciated! NB: I had to add MAX (width, height) pretty much everywhere because width and height were inversed for me.

Yes. You right. And I was fixed this in my post now.

Victor Lavrentyev wrote:

Realisation of enableRetinaDisplay in cocos2d-x version 2.0.4
A more complete solution than in the documentation.
>
In AppDelegate.cpp add this:
>
[…]
>
and this:
[…]

Thank you for your support.

I tried this solution. But I have one question:

It doen’t change the right size pictures when I change the device from iphone to iPhone retina, or change form iPhone retina to not retina.

I have to rebuild the app to see the right size pictures. But the question is go on.


OK,that’s my mistake. I selected a wrong option when “add file to Project”. Got a wrong file path……:stuck_out_tongue: