1
votes

My cocos2d-iphone 1.0.1 game is supposed to be universal.

Currently, it already works fine on non-retina iPad. That is, there is no "2x" button that scales my app or anything. The non-retina iPad uses the -hd graphics from the retina iPhone, so I didn't have to make graphics specifically for the non-retina iPad. I just had to reposition my sprites, but the point is that non-retina iPad is good.

Now comes the iPad Retina.

First of all, I don't have iPad Retina graphics, only -hd iPhone retina ones.

My intention is to have the retina iPad display the game as if it was a non-retina iPad - that is, simply scale the game (the graphics still look good).

The first thing that came to my mind was to modify the director. When you replace or push a scene, the scene will get a scale of 2.0.

Although this indeed scales all the game graphics, it has position issues. Basically, if you have a sprite at the bottom of the screen, with the scene scaled it would not appear in the screen at all, because the scale pushed it further to the bottom.

I am pretty much trying to simulate the functionality of the "2x" button that appears when an iPad runs an iPhone app. In this case, technically I want the retina iPad to look exactly like a non retina iPad.

How may I achieve this?

1
Reading around I noticed people saying that 1.0.1 does not support iPad Retina. I think that this matters only if I had iPad Retina graphics, but I don't, so I guess it's still ok to use 1.0.1.Voldemort
whichever way you do it you will have the problem of scaling (offsets and fonts), but it works for me. I dont enable retina on retina ipads :) and use my -hd textures. Also For backgrounds textures , i systematically use 1136x768 pics ... they work for all devices (cropped on 3.5 iPhones and iPads). The only catch is if you want a background texture that has a 'border' feature, you would need one per device type, and have some 'if' statements at runtime to pick the appropriate texture.YvesLeBorg
@YvesLeBorg: "Don't enable retina mode" - Sir, I feel extremely dumb at the moment. I completely forgot that you could enable/disable it. Please make that the answer.Voldemort
keep in mind that Apple requires apps to support Retina resolution which may mean the app could get rejected if the image quality looks "too blurry" on the Retina iPad.LearnCocos2D
@LearnCocos2D : possible, but some of the stuff i try does not come close to the rendering i get with my -hd stuff. And as a certain Stefen pointed out do me not so long ago, does apple really check anything but 'apple brand correctness' ? I'll know soon enough, about to push a game :)YvesLeBorg

1 Answers

1
votes

whichever way you do it you will have the problem of scaling (offsets and fonts), but it works for me. I dont enable retina on retina ipads :) and use my -hd textures. Also For backgrounds textures , i systematically use 1136x768 pics ... they work for all devices (cropped on 3.5 iPhones and iPads). The only catch is if you want a background texture that has a 'border' feature, you would need one per device type, and have some 'if' statements at runtime to pick the appropriate texture.

here is my AppController startup

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    [director_ enableRetinaDisplay:NO];
    MPLOG(@"iPad device detected : forcing non-retina !");
    [constants setAsIpad];
    isIpadDevice = YES;
}
else {
    isIpadDevice = NO;
    if (![director_ enableRetinaDisplay:YES]) {
        MPLOG(@"Retina Display Not supported");
    }
    else {
        CGSize portrait  = [CCDirector sharedDirector].winSize;
        CGSize landscape = CGSizeMake(portrait.height, portrait.width);
        if (landscape.width >= 568.) {
            [constants setAsIphoneIpodTall];
        } else {
            [constants setAsIphoneIpodSmall];
        }
    }
}

MPLOG(@"Retina display   : %@", NSStringFromBool(kIsRetina));
MPLOG(@"Scale factor     : %.0f", director_.contentScaleFactor);
MPLOG(@"Screen size      : {%.0f, %.0f}", kScreenWidth, kScreenHeight);
MPLOG(@"Tile size        : {%.0f, %.0f}", kTileWidth, kTileHeight);
MPLOG(@"Battle mid point : %@", NSStringFromCGPoint(kBattleMidPoint));
MPLOG(@"Menu width       : %4i", kMapRightMenuWidth);

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices


// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.


[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

if (deviceTypeIpodTall == kDeviceType) {

    [GESprite setDefaultPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    MPLOG(@"Pixel resolution : RGBA8888") ;

}
else {
    if (isIpadDevice) {
        [GESprite setDefaultPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
        MPLOG(@"Pixel resolution : RGBA8888") ;
    }
    else {
        [GESprite setDefaultPixelFormat:kCCTexture2DPixelFormat_RGBA4444];
        MPLOG(@"Pixel resolution : RGBA4444") ;
    }

}
[GESprite defaultPixelFormat];

// If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
// On iPad HD  : "-ipadhd", "-ipad",  "-hd"
// On iPad     : "-ipad", "-hd"
// On iPhone HD: "-hd"
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:@"-hd"];                     // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-hd"];        // Default on iPad RetinaDisplay is "-ipadhd"

// Assume that PVR images have premultiplied alpha

[CCTexture2D PVRImagesHavePremultipliedAlpha:NO];

and in "constants" (hahaha)

+(void)setAsIpad {

kDeviceType          = deviceTypeIpadNormal;
kIsIpad              = YES;
kIsIphoneIpod        = NO;
kIsIphoneIpodTall    = NO;
kMapRightMenuWidth   = 0;
kMapBottomMenuHeight = 0;
kTileHeight          = 80.;
kTileWidth           = 80.;
kScreenWidth         = 1024;
kScreenHeight        = 768;
kIsRetina            = NO;
kScreenSize          = CGSizeMake(kScreenWidth, kScreenHeight);
kScreenMidPoint      = ccp(kScreenWidth / 2, kScreenHeight / 2);
kMidScreen           = kScreenMidPoint;
kBattleMidPoint      = ccp(kScreenWidth / 2 - kMapRightMenuWidth / 2, kScreenMidPoint.y);
}