Enables full screen proportional scaling to adapt to various Android resolutions.

Source: Internet
Author: User

From: http://www.cnblogs.com/yangws/archive/2011/07/22/2114132.html

There is a headache with the development of games with Cocos2d-x, Android resolution is too much.

Although Android supports full screen, but because the length and width ratios of different screens are different, a game designed for a resolution may be increased or squashed on other mobile phones, which is very ugly.

The Cocos2d-x Provides proportional scaling that can be done without modifying the gameCodeThe game image is displayed on different mobile phones. However, due to the different aspect ratio, black borders may be left on both sides of the phone or on both sides of the phone.

The above two multi-resolution adaptation solutions both have disadvantages and are not very nice. So I personally copied a whole "Cocos2d-x full screen proportional scaling multi-resolution adaptation solution", wow click -- Take helloworld when the mouse ,:

This is the size of the game design, hvga, and the effect is perfect.

This is the effect on qvga, and the background image is slightly less displayed.

This is the effect on WVGA, and the background image is shown a little less.

The above effects maintain the aspect ratio in different resolutions, and achieve full screen effects in different resolutions. The UI elements such as blood strip and control bar are also kept in the screen area.

In fact, the method is very simple. Scale the image to cover the screen while maintaining the aspect ratio, and then use the code to obtain the coordinates of the eight vertices and center points at the intersection of the left and right sides and the oblique direction and the screen edge as the positioning point, all the UI elements such as blood strip are located on the Screen Based on 9 positioning points. In this way, you can.

The source code of the example is downloaded. The Code is based on cocos2d-1.0.0-x-0.9.0 and the engine is modified. For details, see readme.txt.

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.