为什么是内容

Why is the content

在 AppDelegate.cpp 中,我们在 bool AppDelegate::applicationDidFinishLaunching() 中有以下代码:

glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL);
auto frameSize = glview->getFrameSize();

// if the frame's height is larger than the height of medium size.
if (frameSize.height > mediumResolutionSize.height)
{        
    director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
     //Add Code to use large assets
}
// if the frame's height is larger than the height of small size.
else if (frameSize.height > smallResolutionSize.height)
{        
    director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
     //Add Code to use medium assets
}
// if the frame's height is smaller than the height of medium size.
else
{        
    director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
     //Add Code to use small assets
}


 director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));

为什么我们取高度或宽度比率的最小值?为什么我们不总是采用 height 或 width ?这不会不一致吗?

由于我们使用的资产大小是固定的(例如,在每个块中我们选择大、中或小资产),那么不同纵横比的缩放比例是否不同,可能具有相同的高度或宽度?这不会导致更糟糕的问题,例如屏幕上的物理和图像不匹配吗?

因为如果您选择最大比例,它将不适合 height/width(取决于方向)。

例如设计分辨率960x640

背景精灵的分辨率1024x768

1024/960 * 1024 ≈ 1092 - 最大值

640/768 * 1024 ≈ 853 - 分钟

因此,如果您选择最大值,您的背景将比设计的更宽,并且 80 像素宽的条纹将超出屏幕范围。

否则,您的背景将适合设计的宽度,旁边有一些黑色条纹 (960-853)/2 像素宽。

Related information