1
votes

I have been working for an iPad game using Cocos2d 2.0, I am facing a problem while loading HD images for the new iPad (Retina Display). But I can't figure out why HD images are not being loaded automatically while executing the code:

Even after adding [director enableRetinaDisplay:YES]; it is still not working. Here is the code sample of when loading image :

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];

I have another image menuBackground-ipadhd.png in the project resources (I can see it from Xcode as well).

Anyone can help ?

2

2 Answers

1
votes

For me it is working in cocos2D 2.0

Change that menuBackground-ipad.png to menuBackground.png Make sure all these lines r found in ur appDelegate and pushScene at the end. Also use onEnter instead of init in layer class.

 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]]; 

//In Layer..

-(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];
}
0
votes

Do not specify the ipad/hd/etc file suffix when loading files. Your problem is caused by using the -ipad suffix here:

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

Remove the suffix to allow cocos2d's do it's job in selecting the correct image:

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