cocos2d iOS Tour: How to write a gopher game (ii): HD support in Cocos2d

Source: Internet
Author: User
Tags gopher

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please tell me, if you feel good please support a lot of praise. Thank you! Hopy;)

Disclaimer: All translations provided by this blog are from the Internet and are for learning and communication purposes only. Also, do not remove this statement when reproduced. In case of any dispute, there is no relationship between the blogger and the person who published the translation. Thank you for your cooperation!

HD Display and Cocos2d

Well, here's the good news-the full support for HD screens is included in the latest version of Cocos2d, and you can use the following 1-2-3 steps to get it done!

    1. The Enableretinadisplay method that calls Ccdirector enables HD support at the beginning of the app. If you use the COCOS2D project template, you only need to remove the comment in the app delegate on that line.
    2. Add the HD Genie to your app, but not use the "@2x" suffix, but instead use the "-hd" suffix for cocos2d. When you load the wizard, the normal screen will be used in the normal picture, the HD screen cocos2d will automatically load high-definition images for you in HD screen.
    3. Now you can use dots in cocos2d instead of pixels to locate them. Note that some APIs (but not many) still have to be processed in pixels-when in this case, their names will have pixel words, otherwise they'll all be dealt with.

In general, the easiest thing to do is to make a picture of the highest resolution (such as the 2X size under the HD screen), and then you can simply shrink the image to the size of the normal iphone.

You might wonder why you have to bother creating two different pictures-why not always call a big picture and then program it to narrow it down? Well, loading textures into memory is an app's memory buster, so if you load HD images on a ching screen, you'll waste a lot of memory.

But don't worry-you don't always have to scale your pictures in Photoshop. Texturepacker actually has the feature of scaling a given picture, it's just being used on our cocos2d trip.

Ipad,iphone and screen aspect ratio

The above makes our processing in the HD screen easier, but what about the ipad?

Well, this will give us a very annoying question: how to make it work on both the iphone and ipad-compare the screen aspect ratio of these devices!

The iphone has a resolution of 480x320 alive with a 960x640-aspect ratio of 1.5, while the ipad resolution is 768x1024 (when the original author was writing the HD ipad was not born yet.), the aspect ratio is 1.33.

This means that if you re-use an image that fills the entire background with an ipad (768x1024) on your iphone, it might not fit perfectly. If you zoom in on the iphone by the width of the image (multiplied by 0.9375), you'll get 720x960, So the extra parts will be cut off!

This is annoying, because not only background images, screen aspect ratio problem also makes cross-device compatibility more difficult.

Here are some solutions, listed here (you can also post your own solution in the comments):

    • In the HD screen iphone (640x960) screen Center, a piece of "playable area" is playable. This will attach a little extra to the border-you can cover it with the background, Players may not even notice. This will allow you to easily reuse footage and transform coordinates on a variety of devices. This is how we blog post in this series.
    • You can use a similar aspect ratio on your iphone, and if you limit "main content" to 684x1024 on your ipad screen, this will bring a 42-pixel border to each edge of your ipad screen. If you can adjust the content to fit the 684x1024 rectangle, You can also reduce the picture for other devices.
    • You can prepare different images for Iphone,ipad and HD screen devices, and their coordinate systems are different. This will have the greatest elasticity, but will also increase the size of the app file

For these challenges-cocos2d currently does not have any help to automatically load the "-HD" suffix image for you on the ipad (the new version of Cocos2d has already been able to select the right picture for the ipad. Cat pig Note), and conversion coordinate system and so on. It all depends on you!

cocos2d iOS Tour: How to write a gopher game (ii): HD support in Cocos2d

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.