How to setup project to Portrait Mode?

Hi!

So, how should i setup a project for portrait mode and ofc with multiple resolution support/universal.

Thanks!

it’s my function for setting up a game for portrait mode:

bool AppDelegate::applicationDidFinishLaunching() {
     ....
    // Set the design resolution
    const float designWidth = 320.0f;         
    glview->setDesignResolutionSize(designWidth, 480.0f, ResolutionPolicy::FIXED_WIDTH);
    setupScaleFactor(designWidth);
     ....
}

void AppDelegate::setupScaleFactor(const float designWidth) {
    auto director = Director::getInstance();
    auto fileUtils = FileUtils::getInstance();
    auto glView = director->getOpenGLView();
    
    const float scaleFactor = glView->getFrameSize().width / designWidth;
    std::vector<std::string> resolutionOrder;
    float contentScaleFactor = 1.0;
    resolutionOrder.push_back("resources-iphone");
    if (scaleFactor > 1.7) {
        resolutionOrder.push_back("resources-iphonehd");
        contentScaleFactor = 2.0;
    }
    
    if (scaleFactor > 2.7) {
        resolutionOrder.push_back("resources-ipad");
        contentScaleFactor = 3.0;
    }
    
    if (scaleFactor > 3.7) {
        resolutionOrder.push_back("resources-ipadhd");
        contentScaleFactor = 4.0;
    }
          
    std::reverse(resolutionOrder.begin(),resolutionOrder.end()); 

    director->setContentScaleFactor(contentScaleFactor);
    fileUtils->setSearchResolutionsOrder(resolutionOrder);
}

Thank you so much! But does
that code make the app support all iOS devices?

Thanks again!

Yes, definitely, i use it for both iOS and Android. But it has flexible height, so this moment should be properly handled in your game logic and ui. Also it uses different sets of images - 1x, 2x, 3x and 4x.

ok but do you know if i can set it, so that the sprites and all that stuff won’t get scaled by them selves?
So that i can scale them manually from the code?

btw, i don’t mind if you don’t answer to the comment below, just as long as if you could answer this one
Thanks so much!

and when i use a 1536x2048 image and run it on a retina, it gets scaled so that i can see the whole image…

take a look:

the image:

And the iPad resolution is the exact same size…But here it it on the iPad:

Regarding iPad and scale.
Basically i use 4x scale for iPad on design width 320, so i provide images with width=1280 instead of 1536 (yes, less than should be).

To get what you want, just instead of 4x - set the contentScaleFactor = 4.8x (1536 / 320).

I configured this function for common use on iOS and Android for simple games, but if you want to get more precise values - you can configure contentScaleFactor values slightly better.