Last Updated: September 09, 2019
·
2.645K
· kencoder

Configuration of Multiple resolution in cocos2d-x 3.0

SDK in use: Cocos2d-x 3.0

Orientation: Portrait (not sure for landscape)

How to use:

  • Add the method "setupResolutionPolicy" in AppDelegate.cpp
  • Call the method inside AppDelegate::applicationDidFinishLaunching right after director->setOpenGLView(eglView);

Method: setupResolutionPolicy

void setupResolutionPolicy(float designW, float designH)
{
      Size screenSize = EGLView::getInstance()->getFrameSize();

     float designRatio = designW / designH;
     float screenRatio = screenSize.height / screenSize.width;

     ResolutionPolicy resolutionPolicy = screenRatio < designRatio ?
               ResolutionPolicy::FIXED_HEIGHT : ResolutionPolicy::FIXED_WIDTH;

    EGLView::getInstance()->setDesignResolutionSize(designW, designH, resolutionPolicy);
}