cocos2d iphone 5 4 inch display support

9 Solutions Collect From Internet About “cocos2d iphone 5 4 inch display support”

Add it to AppDelegate:

[CCFileUtils setiPadRetinaDisplaySuffix:@"your suffix"];
[CCFileUtils setiPadSuffix:@"your suffix"];
[CCFileUtils setiPhoneFourInchDisplaySuffix:@"your suffix"];
[CCFileUtils setiPhoneRetinaDisplaySuffix:@"your suffix"];

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.

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)

Add this to AppDelegate with your chosen suffix:

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

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 480×320 for iPhone
  2. background-hd.png at 960×640 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

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!

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

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

Now cocos2d support iPhone wide screen also.

 -wide.png for iphone 5
 -widehd.png for iPhone 5 HD

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.