Multi-resolution support


#1

I use this code to config multi resolution but when i test on hd resolution. Design resolution still = 1920x1080. Some one can help me to fix it, please.

    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);



    std::vector<std::string> resDirOrders;

    CCSize screenSize = pEGLView->getFrameSize();
    CCLog("Width = %f", screenSize.width);

    //set design screen size to the iPad and ExactFit (image is stretched to fill screen

    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(1080, 1920, kResolutionExactFit);
    
    //if device's screen width is greater than 768, use high definition images
    if (screenSize.width == 1080) {
        resDirOrders.push_back("fullhd");
    //or else, use standard definition
    } else if (screenSize.width == 768){
        resDirOrders.push_back("fullhd");
    } else if (screenSize.width == 720) {
        resDirOrders.push_back("fullhd");
    } else if (screenSize.width == 480) {
        resDirOrders.push_back("fullhd");        
    }



    CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);
    pDirector->setContentScaleFactor(screenSize.width/1080);

    CCLog("Scale = %f", screenSize.width/1080);

#2

Hello!

I’m not sure what’s the problem here, but if you want to support multiresolution without having any resource streched, you have to call something like

pEGLView->setDesignResolutionSize(1024*2, 768*2, kResolutionExactFit);

I use the following code to support multiresolution (iOS devices in particular), called in AppDelegate.cpp right after creating the pDirector:

    // 1. set designResolutionSize (used to scale down and adapt resources to fix in screen)
    // 2. using the screen size, detect the device we are using and set the correct resource path
    // 3. save the type of device in the global variable deviceType
    CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
    std::vector<std::string> searchPaths;
    if(screenSize.height > 640)
    {
        pEGLView->setDesignResolutionSize(1024*2, 768*2, kResolutionExactFit);
        searchPaths.push_back("iPad");
        deviceType = IPAD;
    }
    else if(screenSize.width < 1136)
    {
        pEGLView->setDesignResolutionSize(1024*2, 768*2, kResolutionFixedWidth);
        searchPaths.push_back("iPad");
        deviceType = IPHONE;
    }
    else if(screenSize.width >= 1136)
    {
        pEGLView->setDesignResolutionSize(1024*2, 768*2, kResolutionFixedWidth);
        searchPaths.push_back("iPad");
        deviceType = IPHONE5;
    }
    CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);

Here I detect the device type based on the screen size and then adapt the designed resolution accordingly. The trick is kResolutionFixedWidth or kResolutionFixedHeight. These two parameters will keep one axis (X or Y) fixed, while ‘sacrificing’ a portion of the other. (Keep in mind that this example is for landscape mode, if you turn to portrait you have to change values accordingly)
(Note: you don’t actually need the deviceType line in each if/else, that’s not necessary here)

I hope this can help :slight_smile:

And I’d also suggest these two links which explain quite in details how multiresolution support works (cocos2dx 2.2.2):

http://www.cocos2d-x.org/wiki/Multi_resolution_support (good)
http://www.cocos2d-x.org/wiki/Detailed_explanation_of_Cocos2d-x_Multi-resolution_adaptation (even better link)

Good luck :slight_smile:


#3

I use one folder resource for multi resolution. I desiged it for 1080x1920 and i want to scale down it to fit with 720x1280 resolution. Because use one folder, I shouldn’t to use. Example:

        searchPaths.push_back("iPad");

I don’t know reason when i use:

    pDirector->setContentScaleFactor(screenSize.width/1080);

it not fit my phone screen


#4

mmm can you try to set a 720x1280 when you do not want the HD 1080x1920 resolution? That could work but I fear you should have a different resolution folder and you do not want that, right?


#5

or try

pDirector->setContentScaleFactor(2);

or

pDirector->setContentScaleFactor(0.5);

and see what happens. Because I think screenSize.width remains the same, because it depends on the device real size (not sure about this).

Let me know what happens when you try these!


#6

@davidejones88. I have found my problem.

I used:

    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(1080, 1920, kResolutionExactFit);

kResolutionExactFit: auto scale for me. I can run on 720x1280 but when I test on 768x1280 my game don’t run.


#7

Hey davidejones88,

Only use

    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(1080, 1920, kResolutionExactFit);

and

    pDirector->setContentScaleFactor(screenSize.width/1080);

I don’t set use “host GPU” on emulator and my game don’t run :smiley:


#8

So you fixed this :)?