Cocos2d-iPhone 和 iPhone X 分辨率

Cocos2d-iPhone and iPhone X resolution(Cocos2d-iPhone 和 iPhone X 分辨率)

本文介绍了Cocos2d-iPhone 和 iPhone X 分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能相信我们还在使用 Cocos2d-iPhone 吗?

Can you believe we are still using Cocos2d-iPhone?

有没有人可以修复它以使其与最新的 iPad 和 iPhone X 兼容?

Does anyone have a fix for making it work with the newest iPad's and iPhone X's?

我们的模式是横向.

推荐答案

  1. 如果 cocos2d 版本为 1.0 - 2.1 则更新为 Cocos2d 2.2
  2. 在 Images.xcassets 中添加 iPhoneX 启动画面
  3. 在 CCConfiguration.m 文件中更新了下面的函数.在此我们正在处理 contentScaleFactor 3.

  1. If cocos2d version 1.0 - 2.1 then update it to Cocos2d 2.2
  2. Add iPhoneX splash screen in Images.xcassets
  3. In CCConfiguration.m file updated below function. In this we are handling contentScaleFactor 3.

-(NSInteger) runningDevice
{
    NSInteger ret=-1;

      #ifdef __CC_PLATFORM_IOS

    if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        ret = (CC_CONTENT_SCALE_FACTOR() == 2) ? kCCDeviceiPadRetinaDisplay : kCCDeviceiPad;
    }
    else if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone )
    {
        // From http://stackoverflow.com/a/12535566
        BOOL isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));

        if( CC_CONTENT_SCALE_FACTOR() == 2 ) {
            ret = isiPhone5 ? kCCDeviceiPhone5RetinaDisplay : kCCDeviceiPhoneRetinaDisplay;

            // Guru - Handle iPhone Plus device, iPhoneX
            // - - - - -  - - --  -- - - - -- - -  - - -
            if([[UIScreen mainScreen] scale]==3)
            {
                ret = kCCDeviceiPhone5RetinaDisplay;
            }
        }
        else
        {
            // Guru - Handle iPhone Plus device, iPhoneX
            // - - - - -  - - --  -- - - - -- - -  - - -
            if([[UIScreen mainScreen] scale]==3)
            {
                ret = kCCDeviceiPhone5RetinaDisplay;
            }
            else
            // - - - - -  - - --  -- - - - -- - -  - - -
            ret = isiPhone5 ? kCCDeviceiPhone5 : kCCDeviceiPhone;
        }
    }

    #elif defined(__CC_PLATFORM_MAC)

    // XXX: Add here support for Mac Retina Display
    ret = kCCDeviceMac;

     #endif // __CC_PLATFORM_MAC

      return ret; 

}

  1. 使用 iPhone5HD 中的按钮和其他图像并为 iPhone X 手动加载背景

  1. Use buttons and other image from iPhone5HD and manually load background for iPhone X

CCSprite *bg ;
if([App isIphoneX])
{
   bg = [CCSprite spriteWithFile:@"Background-iphoneX.png"]; // 1624X750 image size
}
else
{
   bg = [CCSprite spriteWithFile:@"Background.png"]; // make sure -hd,-ipad,-ipadhd, -iphone5hd there
}

或者只是缩放背景图像

#define SW ([[CCDirector sharedDirector] winSize].width)
#define SH ([[CCDirector sharedDirector] winSize].height)

CCSprite *bg ;
if([App isIphoneX])
{
      bg = [CCSprite spriteWithFile:@"Background.png"];
      bg.scaleX = SW/bg.contentSize.width;
       bg.scaleY = SH/bg.contentSize.height;

} 

应用代理代码:

-(bool)isIphoneX
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        CGSize screenSize = [[UIScreen mainScreen] bounds].size;
        if (screenSize.width == 812) // portrait height = 812
        {
            return true;
        }
        if([self isIphoneXR]) // Now in this game iPhoneXR, iPhoneXS Max = iPhoneX,
        {
            return true;
        }
    }
    return false;
}
-(bool)isIphoneXR
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        CGSize screenSize = [[UIScreen mainScreen] bounds].size;
        if (screenSize.width == 896 && screenSize.height == 414)
        {
            return true;
        }
    }
    return false;
}

  1. 不要添加 iPhone6、iPhone7、iPhoneXR、iPhoneXSMax 闪屏..系统自动缩放 iphone5 到 iPhone6、iPhone7 等和 iPhoneX 到 iPhoneXR、iPhoneXSMax.你必须使用 iPhone 5、iPhoneX 飞溅

注意:我刚刚支持 iPhoneX 和我的旧游戏的所有设备支持...Apple 最近批准了此更改...成功将 iPhoneX 支持添加到 cocos2d 2.2

NOTE: I just supported iPhoneX and all device support for my old game...Apple recently approved this change...successfully added iPhoneX support to cocos2d 2.2

这篇关于Cocos2d-iPhone 和 iPhone X 分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Cocos2d-iPhone 和 iPhone X 分辨率

基础教程推荐