How to manage resources and screen coordinates in Universal apps?

How to manage resources and screen coordinates in Universal apps?
0.0 0



I´m a little confused.

My game is Universal, and should run with (almost) the same look in iPhone, iPhone Retina mode and iPad (aldo iPad 2).

I can use enableRetinaDisplay, but how to identify if is an iPad?

How do you manage that?

Thanks a lot


This approach will use the iPhone4 retina images 640x960 for the iPad.

In AppDelegate.cpp:

TargetPlatform target = getTargetPlatform();
if (target kTargetIpad)
// ipad
// don’t enable retina because we don’t have ipad hd resource
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(640,960, kResolutionExactFit);
else if (target kTargetIphone)
// iphone
if (pDirector->enableRetinaDisplay(true))
// iphone hd

Use this methods to calculate the real CCPoint coords based on 320x480 for iOS

CCPoint ccpUni(float x, float y){
return ccp(x*scaleCCP,y*scaleCCP); //no offsets added for iPad because of design resolution scale in Cocos2d-x 2.0.2

Another approach is to not call “setDesignResolutionSize” for iPad (non-retina) and position the 640x960 images based on this

CCPoint ccpUni(float x, float y){
return ccp(32+x*scaleCCP,64+y*scaleCCP);

Then you can use larger background images on iPad. Enjoy!


I will try that, thanks for the tips!



So, using setDesignResolutionSize on an iPad, I can use the same HD resources from iphone retina mode, just taking care with the background?
How about the coordinates?

May I assume that the logical dimensions will be 320x480 on every device (of course, using your ‘ccpUni’ function to map the coordinates)?

If I understood correctly, with this approach, if I set the position of a sprite to 160x240, it will be on the center of the screen, on iphone, iphone in retina mode and on ipad?

Tha iPad has a different aspect ratio from the iPhone, in this case, a sprite square in iPhone will be presented as a rectangle (width != height) in iPad, deformed?


@Jose Marin Right. If you just like to use the HD resources on iPad without any deform, then not call setDesignResolution. Place your sprites using the above ccpUni() methods with the offsets.



Thank you.