Disable iPad Retina in Cocos2d v 3 - cocos2d-iphone

In Cocos2d 2.0, I used below code to disable retina for iPad.
if(!IS_IPAD) //In AppController.m
{
[director_ enableRetinaDisplay:YES];
}
Now AppDelegate not has these calls. How to disable retina for iPad only ?

You might want to explore this. I do the same because i want to run all devices from a single set of textures ... and my textures are very 'potent' on all devices, looks fine.
this setup creates a ScreenViewPort that is constant size on all devices , 568x384. All my 'full background' textures are at 1136x768 pixels, able to display all devices. This simplifies layout drastically, but there is a small price to pay. World(0,0) is not ScreenViewPort(0,0). For example, when running on a 4in iPhone (568x320), ScreenViewPort bottom-left is at 0,32 , on an iPad it is at 28,0 ...
Our mileage may vary with new display sizes for iPhone 6, i'll cross that river when i get myself some devices and can ascertain the 'workability' of this.
in AppDelegate :
NSString *kCCFileUtilsSuffixDefault = #"default";
NSString *kCCFileUtilsSuffixiPad = #"ipad";
NSString *kCCFileUtilsSuffixiPadHD = #"ipadhd";
NSString *kCCFileUtilsSuffixiPhone = #"iphone";
NSString *kCCFileUtilsSuffixiPhoneHD = #"iphonehd";
NSString *kCCFileUtilsSuffixiPhone5 = #"iphone5";
NSString *kCCFileUtilsSuffixiPhone5HD = #"iphone5hd";
//NSString *kCCFileUtilsSuffixMac = #"mac";
//NSString *kCCFileUtilsSuffixMacHD = #"machd";
NSDictionary *dic = [CCFileUtils sharedFileUtils].suffixesDict;
[dic setValue:#"-hd" forKey:kCCFileUtilsSuffixDefault];
[dic setValue:#"-hd" forKey:kCCFileUtilsSuffixiPhone];
[dic setValue:#"-hd" forKey:kCCFileUtilsSuffixiPad];
[dic setValue:#"-hd" forKey:kCCFileUtilsSuffixiPadHD];
[dic setValue:#"-hd" forKey:kCCFileUtilsSuffixiPhoneHD];
[dic setValue:#"-hd" forKey:kCCFileUtilsSuffixiPhone5];
[dic setValue:#"-hd" forKey:kCCFileUtilsSuffixiPhone5HD];
[self setupCocos2dWithOptions:#{
// Show the FPS and draw call label.
CCSetupShowDebugStats : #(YES),
// More examples of options you might want to fiddle with:
// (See CCAppDelegate.h for more information)
// Use a 16 bit color buffer:
// CCSetupPixelFormat: kEAGLColorFormatRGB565,
// Use a simplified coordinate system that is shared across devices.
CCSetupScreenMode : CCScreenModeFixed,
// Run in landscape mode.
CCSetupScreenOrientation : CCScreenOrientationLandscape,
// Run at a reduced framerate.
CCSetupAnimationInterval : #(1.0 / 30.0),
// Run the fixed timestep extra fast.
CCSetupFixedUpdateInterval : #(1.0 / 60.0),
// Make iPad's act like they run at a 2x content scale. (iPad retina 4x)
// CCSetupTabletScale2X: #(YES),
}];
[CCTexture PVRImagesHavePremultipliedAlpha:YES];
and in CCFileUtils , a minor mod :)
-(CGFloat) contentScaleForKey:(NSString*)k inDictionary:(NSDictionary *)dictionary{
// XXX XXX Super Slow
// ylb fix for single set of textures
return 2.0f;
// ylb fix : super fast now :)
}

Related

Is it too expensive to run a CCSpawn of a CCRotateBy and CCBezierTo action?

I am trying to run a CCSpawn of a CCRotateBy and CCBezierTo action like so:
ccBezierConfig bezier;
bezier.controlPoint_1 = ccp (startX, startY);
bezier.controlPoint_2 = ccp (endX, endY);
bezier.endPosition = ccp (endX, endY);
id rotate =[CCRotateBy actionWithDuration:3.0f angle:360];
id curve = [CCBezierTo actionWithDuration:3.0f bezier:bezier];
id spawn = [CCSpawn actions:rotate, curve, nil];
[self runAction:spawn];
but it seems to be pretty jerky/jumpy when these actions are running. I have tested it in the simulator (although that is not accurate) it is very jumpy on there, but then I am testing on an iphone 3gs, iphone 4, and iphone 5. The actions seem really smooth on the iphone 5 then it gets a little jerky one the iphone 4 and even more so on the 3gs. The problem I am having is I am not noticing any frame rate drop on any device or the simulator. Any insite would be greatly appreciated.

Cocos2d - retina images not displaying

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?
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!
May be you forgot:
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO];
[sharedFileUtils setiPhoneRetinaDisplaySuffix:#"-hd"];

How does cocos2d use fps_images.png?

Can someone explain to me how cocos2d uses png as a font?
I would like to do something similar as my font only contains numbers.
if you do a global search on the string fps_images.png , your IDE should take you real close to the following lines in cocos CCDirector class (version 2.0) :
FPSLabel_ = [[CCLabelAtlas alloc] initWithString:#"00.0" charMapFile:#"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
SPFLabel_ = [[CCLabelAtlas alloc] initWithString:#"0.000" charMapFile:#"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
drawsLabel_ = [[CCLabelAtlas alloc] initWithString:#"000" charMapFile:#"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
then look up CCLabelAtlas. Your image must be for a fixed width font.
If you want to reuse the same image included to make something other than the FPS display the following code should work:
CCLabelAtlas *scoreLabel = [[CCLabelAtlas alloc] initWithString:#"00.0" charMapFile:#"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
Then to set it to the numbers you want something like this works:
[scoreLabel setString:[NSString stringWithFormat:#"%d", (int)score]];

Cocos2d 2.0 issue loading HD images in Retina Display

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 ?
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];
}
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"];

Why is iPhone 5 briefly Letterboxing and displaying Default.png in Cocos2d?

I have Default-568#2x.png which loads fine.
However, (on the actual device) after it shows the iPhone 5 then displays Default.png, in letter box mode. It then loads the 1136 × 640 px Title Screen - which is fine and what it's supposed to do.
I'm using the default Cocos2d HelloWorld template. I haven't changed anything in the plist or otherwise.
Any ideas?
Why does it load the Default.png and how do you fix this?
Thanks.
In the IntroLayer we have
-(void) onEnter
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) {
background = [CCSprite spriteWithFile:#"Default.png"];
background.rotation = 90;
}
Which is why Default.png is showing up.
How do you keep showing Default-568h#2x.png if you are using the iPhone 5?
I just added another if statement:
if ([UIScreen mainScreen].bounds.size.height == 568.0) {
background = [CCSprite spriteWithFile:#"Default-568h#2x.png"];
background.rotation = 90;
}