gpt4 book ai didi

ios - Cocos2d-iPhone和iPhone X分辨率

转载 作者:行者123 更新时间:2023-12-01 18:37:01 26 4
gpt4 key购买 nike

您可以相信我们仍在使用Cocos2d-iPhone吗?

是否有人有使其与最新的iPad和iPhone X兼容的修复程序?

我们的模式是风景。

最佳答案

  • 如果cocos2d版本1.0-2.1,则将其更新为Cocos2d 2.2
  • 在Images.xcassets中添加iPhoneX初始屏幕
  • 在CCConfiguration.m文件中更新了以下功能。在此,我们正在处理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;

    }
  • 使用iPhone5HD中的按钮和其他图像并手动加载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;
    }
  • 不要添加iPhone6,iPhone7,iPhoneXR,iPhoneXSMax初始屏幕。系统自动将iPhone5缩放到iPhone6,iPhone7等,并将iPhoneX缩放到iPhoneXR,iPhoneXSMax。您必须使用iPhone 5,iPhoneX飞溅

  • 注:我刚刚支持iPhoneX和旧游戏的所有设备支持... Apple最近批准了此更改...已将cocos2d 2.2新增了对iPhoneX的支持

    关于ios - Cocos2d-iPhone和iPhone X分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52531267/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com