How to make an iphone and iphone4-retina compatible app (done in cocos2d) easily adapted to ipad?

六眼飞鱼酱① 提交于 2019-12-22 11:28:08

问题


My question is simple: 1. I made an iphone app all done in cocos2d. 2. I adapted it to iphone4-retina, with all PNG files have their -hd copy.

Run in iPhone, the app displayed correctly (320x480). Run in iPhone4-retina, the app also displayed correctly (640x960).

But run in iPad, if the app is set to iPhone only, it run correctly, but only as iPhone resolution (320x480). If the app is set to iPhone/iPad, of cause it will display wrong.

I'm sure there should be an option that force a retina-compitable iPhone app also run as retina on iPad (apple guys cannot be silly enough to miss it), but I just couldn't find it.

Where's the option? Or, is there an alternative that cocos2d has a same-easy switch to do the job? I do not need suggestions such as using relative coordinates or anything requires modifications more than twenty code-lines.


回答1:


As far as I know, there is no automatic adaptation of an iPhone app to iPad. You still should be able to create a universal app for both iPhone and iPad and then re-create your UI based on whether you are running on one device or the other.

Specifically, you could:

  1. Create an XCode project for a universal app (armv6 and armv7, targeting iPad and iPhone) and import there your existing project (source, resources, settings).

    1b. (you could modify your existing project, but this could be trickier to do correctly.)

  2. add icons and default images as per iPad guidelines in addition to those you have for iPhone;

As to the rest, you could follow a similar approach to the one highlighted here for Xibs:

  1. test for iPad:

    +(Bool)isIpad{ return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad); }

  2. translate image name before loading:

    +(NSString*)properImageFileName:(NSString*)imageName { if ([xxxx isIpad]) { return [NSString stringWithFormat:@"ipad_%@", imageName]; } else { return imageName; } }

Thus, if you are on iPhone, image names are not changed and will follow the iPhone convention for retina display; if you are on iPad, you change the name on the fly and use the right image. (of course, you can use the convention you prefer to identify iPad images).

This should make it pretty trivial, but keep in mind the size toll that having all the images in your universal app tolls.



来源:https://stackoverflow.com/questions/6107528/how-to-make-an-iphone-and-iphone4-retina-compatible-app-done-in-cocos2d-easily

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!