【问题标题】:Cocos2d 2.0 issue loading HD images in Retina DisplayCocos2d 2.0 在 Retina Display 中加载高清图像的问题
【发布时间】:2012-09-23 12:01:36
【问题描述】:

我一直在使用 Cocos2d 2.0 开发 iPad 游戏,在为新 iPad(Retina 显示屏)加载高清图像时遇到问题。但我不明白为什么在执行代码时没有自动加载高清图像:

即使添加了[director enableRetinaDisplay:YES];,它仍然无法正常工作。这是加载图像时的代码示例:

MainBG = [CCSprite spriteWithFile:@"menuBackground-ipad.png"];
CGSize ScreenSize = [[CCDirector sharedDirector]winSize];
MainBG.position = ccp(ScreenSize.height/2,ScreenSize.width/2);
[self addChild:MainBG z:0];

我在项目资源中有另一个图像 menuBackground-ipadhd.png(我也可以从 Xcode 中看到它)。

有人可以帮忙吗?

【问题讨论】:

    标签: cocos2d-iphone retina-display


    【解决方案1】:

    对我来说,它在 cocos2D 2.0 中工作

    将 menuBackground-ipad.png 更改为 menuBackground.png 确保所有这些行都在你的 appDelegate 中找到,最后 pushScene 。在图层类中也使用 onEnter 代替 init。

     if( ! [director_ enableRetinaDisplay:YES] )
            { 
                CCLOG(@"Retina Display Not supported");
            }
    
        CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
        [sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used
        [sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
        [sharedFileUtils setiPadSuffix:@"-ipad"];                   // Default on iPad is "ipad"
        [sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];    // Default on iPad RetinaDisplay is "-ipadhd"
    
        [director_ pushScene: [IntroLayer scene]]; 
    

    //在层中..

    -(void)onEnter
    {
        [super onEnter];
        MainBG = [CCSprite spriteWithFile:@"menuBackground.png"];
        CGSize ScreenSize = [[CCDirector sharedDirector]winSize];
        MainBG.position = ccp(ScreenSize.height/2,ScreenSize.width/2);
        [self addChild:MainBG z:0];
    }
    

    【讨论】:

      【解决方案2】:

      加载文件时不要指定ipad/hd/etc文件后缀。您的问题是由于在此处使用 -ipad 后缀引起的:

      MainBG = [CCSprite spriteWithFile:@"menuBackground-ipad.png"];
      

      去掉后缀,让 cocos2d 可以选择正确的图像:

      MainBG = [CCSprite spriteWithFile:@"menuBackground.png"];
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多