5

I have been looking everywhere for this but with no luck.

How do I prepare my cocos2d based game for bigger 4 inch display of the iPhone 5? My app is working but i want to enhance it for the bigger 4 inch display. Cocos2d uses its own suffixes for retina display images. For retina display of the iPhone 4 and 4S it is image-hd.png. Is there a suffix for iPhone 5? How do I accomplish this?

Cheers.

Majster
  • 3,611
  • 5
  • 38
  • 60

9 Answers9

12

There is no extra file suffix for iPhone 5, after all it's only 176 pixels (88 points) wider. It's treated like a regular Retina phone, hence cocos2d will load the -hd files.

The rest is just about positioning your images depending on the device. The simplest way is to just treat the 44 points on either side as a "dead zone" where no user input can occur and where there's no guarantee the user can see game objects.

Update: cocos2d 2.1 added the -widehd suffix. It was said that 2.1 final release will have the suffix renamed to -iphone5hd.

In light of future screen sizes I sould personally set and use a -568hd suffix because other phones beside iPhone 5 may have the same resolution. Naming the suffix after a specific iPhone model is a tad short-sighted to say the least.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
8

Add it to AppDelegate:

[CCFileUtils setiPadRetinaDisplaySuffix:@"your suffix"];
[CCFileUtils setiPadSuffix:@"your suffix"];
[CCFileUtils setiPhoneFourInchDisplaySuffix:@"your suffix"];
[CCFileUtils setiPhoneRetinaDisplaySuffix:@"your suffix"];
eugen
  • 8,916
  • 11
  • 57
  • 65
user2052384
  • 96
  • 1
  • 1
7

Not sure why everyone is saying there isn't.

The suffix is -568h for iPhone5/iPod Touch 5th (so the 4 inch retina displays).

The total list:

  • -hd (iPhone 4/4S, iPod Touch 4th)
  • -568h (iPhone 5, iPod Touch 5th)
  • -ipad (iPad 1st/2nd)
  • -ipadhd (iPad 3rd/4th)
Marko
  • 86
  • 1
  • 4
7

Add this to AppDelegate with your chosen suffix:

if((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && ([[UIScreen mainScreen] bounds].size.height == 568)) {
    [sharedFileUtils setiPhoneRetinaDisplaySuffix: @"-your suffix"];
}
2

It took me awhile to figure this out, since I'm new to cocos2d. So I thought a recap might be helpful for those like me. In cocos2d 2.1, all you have to do is creating graphics for the target screen sizes and follow cocos suffix naming convention. Note that cocos's suffix convention is not the same as iOS's.

In my case, I have a background image that occupies the full screen. So, I made...

  1. background.png at 480x320 for iPhone
  2. background-hd.png at 960x640 for iPhone retina (3.5")
  3. background-iphone5hd.png for iPhone5 retina (4")

And use the following code to load the image into CCSprite. Cocos will figure out which image to use for you.

CCSprite *background = [CCSprite spriteWithFile:@"background.png"];
background.position = ccp(background.textureRect.size.width/2,
background.textureRect.size.height/2);
[self addChild:background];

For an element like a character that doesn't occupy the full screen, cocos2d will pickup character-hd.png automatically in iPhone5. There is no need to create character-iphone5hd.png version.

You can read more about this in version 2.1 release note at https://github.com/cocos2d/cocos2d-iphone/wiki/cocos2d-v2.1-release-notes

voratima
  • 409
  • 3
  • 6
2

This is how i did it for cocos2d v2.1-beta4.

In CCFileUtils.h i added:

- (void)setIphone5HDSuffix:(NSString *)suffix;

In CCFileUtils.m:

- (void)setIphone5HDSuffix:(NSString *)suffix
{
   [_suffixesDict setObject:suffix forKey:kCCFileUtilsiPhone5HD];
}

In AppDelegate.m:

[sharedFileUtils setIphone5HDSuffix:@"your_suffix"];

And that's enough!

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
1

Did you follow the following post, adding the default image for it, named Default-568h@2x.png with a resolution of 1136x640?

How to develop or migrate apps for iPhone 5 screen resolution?

If it does not work, I found this post on cocos2d forum, containing a lot of infos:

iPhone 5 1136 x 640 screen resolution: http://www.cocos2d-iphone.org/forum/topic/39491

Community
  • 1
  • 1
iMathieuB
  • 1,168
  • 10
  • 11
  • Yes I found both. But I still dont know how do I name .png files for sprites. I have a splash screen for my app named Default-568h@2x.png and its woking. Question left how do I `CCSprite *player = [CCSprite spriteWithFile:@"player.png"];` for the 4 inch display? Cocos2d knows to use -hd suffix when retina display, how do I tell it which image to use for 4 inch retina? – Majster Sep 19 '12 at 20:12
  • I found no mention of a new suffix in latest release notes and documents from cocos2d. I think you may programmatically detect and specify your custom player-568h.png file for now. And change that when they will give a new cocos2d release... – iMathieuB Sep 19 '12 at 20:53
0

Now cocos2d support iPhone wide screen also.

 -wide.png for iphone 5
 -widehd.png for iPhone 5 HD
Guru
  • 21,652
  • 10
  • 63
  • 102
0

I was just playing around with suffixes in Cocos2D 2.1-rc1 and was able to get it to automatically load a iPhone5 file with the "-iphone5hd" suffix, not changing anything in AppDelegate in the sharedFileUtil section of code. Hope that helps, also.