为什么是内容

时间:2016-11-25 05:30:30

标签: cocos2d-x cocos2d-x-3.0 cocos2d-x-3.x

在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));

为什么我们采用高度或宽度比率的MIN?为什么我们不总是采取高度或宽度?这不一致吗?

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

1 个答案:

答案 0 :(得分:0)

因为如果你选择最大比例,它就不适合身高/宽度(取决于方向)。

例如设计的分辨率960x640

后台精灵的分辨率1024x768

1024/960 * 1024 ≈ 1092 - max

640/768 * 1024 ≈ 853 - min

所以,如果你选择最大值你的bg将会更宽,然后设计并且80px宽的条纹将不在屏幕上。

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

Related information