compiling for several iOS targets

just wondering how i would approach this? id like to make a big (but not cpu/memory intensive) game and target the slowest iphone and ipad, but if someone were to play on a new iphone/ipad i would like them to have higher quality assets. am i correct in assuming openframeworks could support this? some kind of device query setting some environment variables within xcode? and can xcode have multiple targets? i will just be using the simulator for the time being.

good question. Currently if you want to develop for the ios6 you must have the latest version of x-code.
this means that armv6 is not supported… so that defacto limits your backwards compatibility. in general apple makes it very difficult for developers…

The way I do it personally is…

I use the latest x-code etc… add armv7 & armv7s Deployment Target (>4.3)
create a universal project add the images named: Default-568h@2x.png etc// in the data file. (splash screens activate the fullscreen mode on ipads iphone5)
then go to Info.plist and manually add prefixes for icons for all the devices (otherwise the binary will be rejected, if you try to add the icons manually (like drag and drop) it brakes (of_preRelease_v007_iphone) and results to duplicated directories in the archived app so it will double the size of your game. so add icons to project manually. from info.plist inside xcode.


I create 3 extern booleans in a global .h/.mm file (isRetina, isIpad,isPhone5)

In the main I detect the device. and accordingly modify the extern booleans

I extend the ofImage object to a UofImage object. (universalofImage)

using the booleans the object will load (if assets available) the appropriate images according to the device

for example if nonretina nonipad then load “image_3g.png” if retina&ipad3 “image_hd.png” otherwise… image.png

above EVERYTHING I use the ofScale();

something like:

void mygame::loop(){



scaledWidth/height float
it’s again an extern float that accordingly to the global booleans I calculate the proper value… that will scale my
320x480 game to fit the device. for example:

if (isRetina && isiPad){
scaledwidth = 4.8;
scaledheight = 4.2666;

But this method brakes the mouseX,mouseY and ofGetWidth()/height

So again I create a float called: GlobalMouseX/y and I map it to 320/480

and a GlobalofGetWidth()/height() float that returns 320/480

So the idea is that you write one code for 320/480 aspect ratio and it is being scaled up to fit the resolution of each device the way ofScale works allows a high resolution image to be drawn in retina screen in a smaller size but look sharp and nice.

so you draw your image like uimage.draw(x,y,30,30); the image that is drawn is actually a 60x60 image and it is scaled up.

awesome post, thanks. can I develop with the iOS6 SDK and use the deployment target settings so that the universal binary will be able to run on the specified lowest iOS? so you have 4.3 selected, does that mean your program will run on any device running 4.3 or later? in my test project i set up today (after upgrading my OS to mountain lion and Xcode to 4.5 and iOS sdk to 6.0) things run fine in the IOS6 simulator but break in any earlier version, i thought it may be because the project uses IOS6 and needs an earlier SDK.

the way you handle the drawing using a scale and bools to decide what image to draw is just what i was looking for too.

I can post code if you want (regarding the detection of devices - universal ofImage -mapping scaling- mouseX-mouseY) although is really easy to write…

Iphone5 can handle apps/games that target older sdks. if you want a device that runs older skd like 5.0 to support an app that was archived using 6.0sdk you must make sure that you 've included armv7 and changed the settings in x-code to set deployment target that includes the sdk of your device…

but in general …is good to know that apple wants you to use all the latest software and screw older users. they try to force people buy their new stuff… you know how it is… it’s really a pain. I prefer snow leopard If I wasn’t developing I wouldn’t go anywhere near m-lion…

cool, just one more question. setting the opengl context in main doesnt have any effect when using the iphone simulator, when i switch between iphone6 and ipad6 retina, the image is just scaled up. how do you define the screen area?is there some kind of osSetWindow() that runs in the background based on detected environment?

Ok I will upload a sample project.

Here is the thing. The only way that apple allows developers to activate a larger screen (retina/ipad3/iphone5) is by including the appropriate splash screens.

The ofsetup openGl object does absolutely nothing. If you run the code without the splash object it will just draw the image bigger but the resolution of the project will be 320x480.

by adding a Default@2x.png inside the data folder you activate the retina screen. so the ofGetScreenWidth/height method will return 640x960.

so you will have to scale everything up by 2.

Then draw the universal image. but don’t just put the place you want to put it. put the size as well.

for example uimage.draw(0,0,320,480)

now if it’s retina, when you loaded uimage.loadImage(“picture.png”); it will load the picture “picture_2x.png” automatically that is 640x960 but it will be scaled down by 2 since you use 320,480 in the draw so it will appear normal and hd

a sample universal project in x-code 4.2 using of: oo7
device detection scale mapped mouse fixed ofgetWidth() added icons and universalImage:

in case anyone downloaded the previous file and didn’t work, try this.

Write one code and scale it up to fit all apple devices, if you provide specified images in hd or low res for non retina it will load them accordingly, otherwise it will load the standard image for all devices.

nice one, thanks. I just thought, the ipad and iphone have different aspect ratios. do you compile the same project across those different devices or do you just keep each project to its own device but support the different OS’s?

yes they do have different aspect ratios but If an image is 640x1136 and you draw it 320x480 and then scale it up by 2x2.366 the image will appear on the screen 100%correctly and not stretched. (just like in the example) If you use the same images for devices with different aspect ratios they will obviously appear stretched but from my experience that is not really such a big deal. Try it for yourself you really can’t tell much of a difference. you will be surprised how many big players do the same in their games, if you prepare separate images for all devices then the size of your game will grow exponentially and that’s a major drawback, yet alone the fact that you must write separate code for each device. It depends from case to case ofcourse. For some apps it’s a lot easier, all you need is load different images, in other cases it’s just better to stretch things up.
whatever you do you must plan ahead and make your decisions from the very start. Last thing you want is develop a game without having in mind how you will transfer it on the ipad.

I wish you the best in any case

Personally I use that technique to cover all devices in one version. I don’t have separate versions.

cool, i think i need some time to wrap my head around the skew factor of different resolution ratios. thanks for your help.