Monday, July 23, 2012

iOS game development: handling different screen resolutions

ASSETS SIZES

My favorite option for iOS game development is to use just the exact size for the assets that each device actually uses. It basically is (at the time of writing this article):

  • iPhone 3G/iPod3: 480x320
  • iPhone 4/iPo4: 960x640
  • iPad 1,2: 1024x768
  • iPad 3 (or "new iPad"...): 2048x1536
This gives us the top quality for each device and the best user experience. Since there is an important variety of necessary assets if we want to cover all the devices, I do not recommend to build universal versions. I recommend a version for the small devices, and then another for iPad, but that depends a lot on each game.

How does this work? You first need to enable the retina mode:

pDirector->enableRetinaDisplay(true);

You just need to have one call for each texture. For example: CCSprite::create("mypic.png"); and then Cocos2dX will actually look for the adequate file to the current iOS device. This is:

mypic.png
mypic-hd.png
mypic-ipad.png
mypic-ipadhd.png

And that's it! Cocos2DX will automatically load the necessary asset for the current platform, there is no need to check what is the platform in your own code, what is great.

But I have more! :-) You can actually change the predefined suffixes if you want to (not sure why anyone might want to do it, but you have the choice):

    CCFileUtils::setiPadSuffix("-mysufix");
    CCFileUtils::setiPadRetinaDisplaySuffix("-mysufix");
    CCFileUtils::setiPhoneRetinaDisplaySuffix("-mysufix");

BUG: The problem comes when you want to create a game for iPad only. Cocos2D-X will always look for xxx.yyy file. This means that having your xxx.ipad.yyy and xxx.ipadhd.yyy is not enough, and if you don't put the xxx.yyy file in the project, the execution will fail.



POSITIONING ASSETS

Then, the next interesting thing is about positioning. All the small devices share a device width and heigh of 480x320 points, so you can use the same absolute positioning for them if you want. iPad and iPad hd will also share the 1024x760 points.

I don't like relative positionings... I prefer to control where is everything on the screen. But anyway, if anyone finds a good solution to use the same positioning system for iPhone and iPad please let me know :-)

Please feel free to follow me on twitter and share your thoughts :-) @jboschaiguade

6 comments:

  1. Thanks! What about Android? Should I use the Android's naming convention for my assets? It would be very useful for a beginner like me to read about that. And there I cannot use absolute positioning because there are so many screens. Also, currently I am looking for a way to handle both orientations, and I need to find out how to rescale my world when orientation changes. Could you write on that?

    ReplyDelete
    Replies
    1. unfortunately android doesnt work this way. I dont have a lot of experience on android with cocos but in a previous post I was talking about this. But I can't ensure its the best solution, try to ask at the cocos2d-x forum.

      This is how we did pixel colors both for android and ios. Not the best solution but you can use exactly the same textures on all devices.

      Delete
  2. Thanks for the post, most useful......Did you ever find a good solution to use a relative positioning system? I don't really want to go down the route of two separate apps to support phone/pad.

    ReplyDelete
  3. Hi,

    You can use CocosBuilder, at least for UI's, but even for gameplay on many games.

    JB

    ReplyDelete
  4. Which version of cocos2dx used in this tutorial?

    ReplyDelete
    Replies
    1. sorry, but the post is outdated. Now I'm posting to www.plungeinteractive.com/blog

      Delete