【问题标题】:Cocos 2d - launch image resizes from 568h to @2x on iPhone 5 automatically?Cocos 2d - 在 iPhone 5 上启动图像大小从 568h 自动调整为 @2x?
【发布时间】:2013-08-20 23:23:19
【问题描述】:

你好!我正在使用 Cocos2d 运行最基本的 Hello World 应用程序,它完全没有从 Xcode 中最基本的 cocos2d 模板进行修改。

当我启动模拟器时,iPhone 5 的启动图像会自动加载 - 但是几秒钟后,启动图像会切换到 iPhone 4 的默认@2x,因此在两侧都有两个未使用空间的小条纹发射图像。

为什么会这样?以及如何使启动图像在几秒钟后不会自动切换到 iPhone 4 的较小版本?

谢谢

【问题讨论】:

    标签: cocos2d-iphone


    【解决方案1】:

    在 IntroLayer.mm 中添加以下代码:

        CCSprite *background;
        if( IS_IPAD)
        {
             if(IS_RETINA)
                background = [CCSprite spriteWithFile:@"Default-Portrait@2x~ipad.png"];
             else 
                background = [CCSprite spriteWithFile:@"Default-Portrait~ipad.png"];
        }
        else
        {
            if(IS_IPHONE5)
                background = [CCSprite spriteWithFile:@"Default-568h@2x.png"];
            else
            {
                if(IS_RETINA)
                    background = [CCSprite spriteWithFile:@"Default@2x.png"];
                else
                    background = [CCSprite spriteWithFile:@"Default.png"];
            }
    }
    

    使用的宏:

    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    #define IS_IPHONE5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
    #define IS_RETINA ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))
    

    【讨论】:

      猜你喜欢
      • 2012-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多