iOS上的缩放分辨率

时间:2019-03-10 00:47:31

标签: ios cocos2d-x levelhelper

我正在用cocos2d-x进行游戏,但是在设置正确的designResolutionSize时遇到问题。我也在使用Level Helper,并且对于新设备已经过时了,因此我使用以下方法为不同设备设置了designResolutionSize:

auto frameSize =  Director::getInstance()->getOpenGLView()->getFrameSize();
if(frameSize.width == 2048.000000){
    sceneSize = Vec2(2048.000000, 1536.000000);
    CCLOG("Is IPad 5TH or 6TH or Air or Air2 or iPad Pro 9.7");
}
else if (frameSize.width == 2224.000000) {
    sceneSize = Vec2(1112.00000,834.00000);
    CCLOG("Is iPadPro 10.5");
}
else if (frameSize.width == 2388.000000) {
    sceneSize = Vec2(1194.00000,834.00000);
    CCLOG("Is iPadPro 11");
}
else if (frameSize.width == 2732.000000) {
    sceneSize = Vec2(1366.00000,1024.00000);
    CCLOG("Is iPadPro 12.9 All Gen");
}
else if(frameSize.width == 1136.000000){
    sceneSize = Vec2(1136.000000, 640.000000);
    CCLOG("Is iPhone 5S o SE");
}
else if(frameSize.width == 1334.000000){
    sceneSize = Vec2(1334.000000, 750.000000);
    CCLOG("Is iPhone 6/6s/7/8");
}
else if(frameSize.width == 2208.000000){
    sceneSize = Vec2(2208.000000, 1242.000000);
    CCLOG("Is iPhone 6/6s/7/8 - PLUS");
}
else if(frameSize.width == 2001.000000){
    sceneSize = Vec2(1104.000000, 621.000000);
    CCLOG("Is iPhone 6/6s/7/8 PLUS - WITH ZOOM");
}
else if(frameSize.width == 2436.000000){
    sceneSize = Vec2(1218, 562);
    CCLOG("Is iPhone X, XS");
}
else if(frameSize.width == 1792.000000){
    sceneSize = Vec2(1218, 562);
    CCLOG("Is iPhoneXr");
}
else if(frameSize.width == 1624.000000){      
    sceneSize = Vec2(1218, 562);
    CCLOG("Is iPhoneXr - WITH ZOOM");
}
else if(frameSize.width == 2688.000000){
    sceneSize = Vec2(1344.000000, 621.000000);
    CCLOG("Is iPhoneXsMax");
}
else{

    UserDefault::getInstance()->setBoolForKey("Zoomed",true);
}


float ratio = curDev->getRatio();
sceneSize.width = sceneSize.width/ratio;
sceneSize.height = sceneSize.height/ratio;

Director::getInstance()->setContentScaleFactor(ratio);

aspect = 2;

if(aspect == 0)//exact fit
{
    sceneSize = designResolutionSize;

    Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designResolutionSize.width,
                                                                      designResolutionSize.height,
                                                                      ResolutionPolicy::EXACT_FIT);
}
else if(aspect == 1)//no borders
{
    Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designResolutionSize.width,
                                                                      designResolutionSize.height,
                                                                      ResolutionPolicy::NO_BORDER);
}
else if(aspect == 2)//show all
{
    Director::getInstance()->getOpenGLView()->setDesignResolutionSize(sceneSize.width,
                                                                      sceneSize.height,
                                                                      ResolutionPolicy::SHOW_ALL);

    designOffset.x = (sceneSize.width - designResolutionSize.width)*0.5;
    designOffset.y = (sceneSize.height - designResolutionSize.height)*0.5;
}

如果某些设备启用了缩放功能,则frameSize会更改,因此游戏会错位所有图层,从而导致游戏加载错误。现在,我设置了一个messageBox来告诉用户,他必须将缩放显示启用到标准状态才能玩游戏,但这不是解决方案。

我已经为某些设备修复了此问题:

  • iPhone 6,7和8在缩放模式下,将sceneSize设置为1136 x 640(iPhone SE分辨率)

  • 缩放模式下的加号版本,将sceneSize设置为2001 x 1125

  • 设置为缩放模式的iPhone Xr,场景大小为1624 x 750

我找不到iPhoneXsMax和第三代iPad Pro 12.9inch的变焦分辨率。 有人可以告诉我这些缩放分辨率,或者可以通过其他方法帮助我吗?

0 个答案:

没有答案