4

Simply trying to test retina display. I setup the director like this:

CCDirectorIOS* director = (CCDirectorIOS*)[CCDirector sharedDirector];
    director.wantsFullScreenLayout = NO;
    director.projection = kCCDirectorProjection2D;
    director.animationInterval = 1.0 / 60.0;
    director.displayStats = YES;
    [director enableRetinaDisplay:YES];

I create two versions of the file in Photoshop - outline-hd.png and outline.png. I color the HD version red so I can tell if it's being displayed.

Display code:

CCSprite *border = [CCSprite spriteWithFile:@"outline.png"];
[self addChild:border];

Yet it is the non-hd image that gets displayed on my iPhone5. Why?

soleil
  • 12,133
  • 33
  • 112
  • 183
  • did you add the outline-hd.png to the project? – CodeSmile Mar 02 '13 at 19:00
  • Yes, and in fact, if I specify spriteWithFile:@"outline-hd.png", it will display it. It was my understanding that Cocos2d should do this automatically, otherwise I have to use if/else statements everywhere to determine whether or not to use the retina graphics. – soleil Mar 02 '13 at 19:02
  • It does so automatically. Which cocos2d version btw? You may need to upgrade for iphone 5 support (verify with Retina iphone simulator) and/or add the Default-568h@2x.png file. Check out CCFileUtils to find out what exactly happens when cocos2d tries to load the image. – CodeSmile Mar 02 '13 at 19:07
  • I have the Default-568h@2x.png file and the rest of the app works with the iPhone5. What's also confusing is that border.contentSize is the same (60,60), whether I specify the -hd extension or not. – soleil Mar 02 '13 at 19:11
  • contentSize is always the same because it's in points, not pixels. Is this in a mixed UIKit+Cocos2D app? Perhaps things are different there. Try with 2.1 rc0a or a blank project just to verify. – CodeSmile Mar 02 '13 at 21:03
  • @LearnCocos2D Yes, this is a mixed project. I tried it in a blank project and it worked fine. So what are we to do in a mixed project? Is there no support for retina graphics in that case? – soleil Mar 02 '13 at 21:49
  • If I name the retina file @2x it will display the retina version. I really don't see where the line is drawn between a cocos2d project and a UIKit project. – soleil Mar 03 '13 at 06:17

2 Answers2

1

I came across this question while trying to solve the exact same problem in my own project. Had to dig around in the cocos2d source to figure it out. The problem is that the director's enableRetinaDisplay:YES method doesn't work unless the director's view is set. So, it needs to be called after the glView is set up, and you've called setView on the director:

CCGLView *glView = [CCGLView viewWithFrame:aFrame
                                   pixelFormat:kEAGLColorFormatRGBA8
                                   depthFormat:0
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];

[[CCDirector sharedDirector] setView:glView];
NSLog(@"glView is set, enable retina...");
[[CCDirector sharedDirector] enableRetinaDisplay:YES];

This should fix the problem for you!

jkira
  • 1,150
  • 6
  • 7
0

May be you forgot:

CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO];         
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];  
B.S.
  • 21,660
  • 14
  • 87
  • 109