Cocos2d-x Background image sets required for iphone/ipad - iphone

In Cocos2d Obj.C Game, I used below code to display background.
CCSprite *bg = [CCSprite spriteWithImageNamed:#"Background.png"];
In folder, I put these image sets
Background.png 320x480
Background-hd.png 640x960
Background-ipad.png 768x1024
Background-ipadhd.png 1536x2048
This code is arround 3 years old. Now what are the required image sets for background in cocos2d-x ?
In Cocos2d-x,
auto sprite = Sprite::create("Background.png");
How to read background for iphone5/iphone6/iPhone7/iPadpro in cocos2d-x ? What are file extension?
what sets ideal game programmer use now?

Related

Sprite Atlas and #2x images

When using texture atlas (iPhone5) do I have to include sprite images at both normal and normal#2x sizes (even though I am only targeting retina devices). I thought I could getaway with only adding the #2x versions but sadly when I run the application the sprites come out a lot bigger than they should be (nearly 4x), I only get the right size sprites displayed when I add the normal (#1x) images to the atlas as well.
EDIT:
Starting a new project file in Xcode, if you want an image to fill the whole device display (iPhone5/5S at the maximum resolution) you need to use the #2x extension (in this case there is no "background_003.png" in the Xcode project so just the #2x version is fine)
// SETUP BACKGROUND FRAME IS {320, 568} POINTS
// IMAGE "background_003#2x.png" = 640 x 1136 Pixels
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:#"background_003"];
[background setAnchorPoint:CGPointZero];
[background setPosition:CGPointZero];
[self addChild:background];
If you add the correct sized image (640 x 1136) without the #2x Xcode takes the image and scales it incorrectly by the devices 2.0 point size, resulting in an image that is twice as big as the display.
// SETUP BACKGROUND FRAME IS {320, 568} POINTS
// IMAGE "background_001.png" = 640 x 1136 Pixels
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:#"background_001"];
[background setAnchorPoint:CGPointZero];
[background setPosition:CGPointZero];
[self addChild:background];
RESULT:
After a little bit of testing this morning I have now realised that my problem was the result of adding sprite frames in an atlas without the #2x postfix and then renaming them to include the missing #2x. It would seem that when using folder.atlas Xcode creates a plist somewhere that references the files, I can't find this and it only seems to get updated when you first add your atlas to your project. After deleting and re-adding the atlas Xcode started correctly displaying the #2x images at the right scale.
The moral of this story is therefore: if you change an atlas or its contents, make a copy, delete it from your Xcode project and re-add it again. Create all your artwork at retina resolution and add the #2x postfix to all your files, you only need none retina files (without the #2x if your targeting a none retina device) Finally when referring to art assets in code don't use the #2x postfix, so even though your monster sprite art is called "Monster_0001#2x.png" you should be referring to it in code as "Monster_0001" Xcode will work out the #2x bit for you behind the scenes, also if your using PNGs (which you should be) it will even add the ".png" for you too.
// THE ART ASSET ON DISK IS CALLED: "Monster_0001#2x.png"
SKSpriteNode *spriteMonster = [SKSpriteNode spriteNodeWithImageNamed:#"Monster_0001"];
If you only support Retina devices just add files without the #2x and you'll be fine.

Cocos2d Background image not showing properly on retina simulator and devices

I have implemented below code in cocos2d for showing background image and this code is working fine except in Retina devices. Background images is not scaled or set properly. It is working fine on iPad 2 with IOS 6.0 but not on Retina iPad (3) 6.0 and Retina simulators. I have even tried samples from github and ray wonder -samples. All codes have same issues. Did anybody face same kind of issue ?
CCSprite *bg ;
bg = [CCSprite spriteWithFile:#"GameBGiPad1.png"];
bg.anchorPoint = CGPointZero;
[self addChild:bg z:-2];
I have included below lines to enable retina display and also added image with name "GameBGiPad1-hd.png" but it is showing black background on retina after adding below code:-
Also included below code in app delegate:-
if( ! [director enableRetinaDisplay:YES] )
CCLOG(#"Retina Display Not supported");
Both images are not part of sprite sheet but placed in images folder.
Cocos2d 1.0 : Not supports iPad retina display.
Cocos2d 2.0 : Use below naming convention.
For iPad retina you need to put image with extension -ipadhd.png
GameBG.png - For iPhone
GameBG-hd.png - For iPhone HD
GameBG-ipad.png - For iPad
GameBG-ipadhd.png - For iPad HD
GameBG-iphone5hd - For iPhone5

iOS not using -568h#2x.png

I have 3 images:
test.png
test#2x.png
test-568#2x.png
In IBOutlet, a UIImageView is set to display test.png.
On iPhone 3.5in without retina, it's displaying test.png
On iPhone 3.5in with retina, it's displaying test#2x.png
But on iPhone 4in with retina, it's displaying test#2x.png!!!
What's going on?
Thanks!
The -568#2x suffix only applies to the Default.png launch images. There is no special suffix used by UIImage imageNamed: (or the other UIImage methods). If you need a special image on the 4" screen, you need to add code to get the desired image yourself.
The following works for the iPhone. For the iPad, you would need additional images.
For the three versions of the background image, use the following names:
background-480h.png (320x480)
background-480h#2x.png (640x960)
background-568h#2x.png (640x1136)
(You don't need a "-568h.png" image because there's no 320x568 iPhone screen.)
When you set the background image, simply append the screen height to the image name:
NSString* imageName = [NSString stringWithFormat: #"background-%ih", (int)[[UIScreen mainScreen] bounds].size.height];
[view setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: imageName]]];
iOS automtically appends the "#2x" if applicable.
You could omit the "h" after the height in the image names, but I think it's nice to emulate the iOS convention for the default image.
I know it's an old thread but I was having trouble with the new screen sizes for iPhone 6/6+.
What I did is to use this naming convention for different image files:
none if #1x small old phones
#2x for iPhone 4
-568h#2x for iPhone 5
-667h#2x for iPhone 6
#3x for iPhone 6 Plus
And then to automatically generate (full size) images just by including the code from this Gist in the project:
https://gist.github.com/kevindelord/fe2e691d06ab745fbb00
You have nothing else to do. When you instantiate an image in your code:
[UIImage imageNamed:#"background.png”];
The categorised class from the Gist will automatically create an image corresponding to the current device.
There is a Pod for it UIImage+Autoresize documented on CocoaDocs.

cocos2d iphone 5 4 inch display support

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.
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.
Add it to AppDelegate:
[CCFileUtils setiPadRetinaDisplaySuffix:#"your suffix"];
[CCFileUtils setiPadSuffix:#"your suffix"];
[CCFileUtils setiPhoneFourInchDisplaySuffix:#"your suffix"];
[CCFileUtils setiPhoneRetinaDisplaySuffix:#"your suffix"];
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...
background.png at 480x320 for iPhone
background-hd.png at 960x640 for iPhone retina (3.5")
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 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
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.

How to update 2D iPhone game to be compatible w/ iPhone 4's retina display?

What are the necessary steps to update an existing OpenGL ES 1.1 based 2D iPhone game to be compatible w/ the iPhone 4's retina display? I'm still using the Texture2D class that came w/ Apple's CrashLanding (download) sample code.
After reading Apple's documentation, watching the WWDC video (session 134 "Optimize Your iPhone App for the Retina Display"), and looking at Cocos2D sample code I'm still confused.
I believe the required steps include:
passing high-res artwork (w/ "#2x" appended) to [UIImage imageNamed:#"image.png"]
changing the "contentScaleFactor" from 1.0 to 2.0 (where?)
updating the arguments to glOrthof to include the contentScaleFactor
adjusting the size of the glViewport
Please note that I'm relatively new to OpenGL.
Thanks for your help!
You should keep the 320x480 image, and provide the 640x960 image with a different name. Suppose the 320x480 image is called foo.png, then name the 640x960 one foo#2x.png.
The system will then automatically select the higher resolution one on iPhone 4, without any change in code — assuming you were using [UIImage imageNamed:#"foo.png"].