Cocos2d-x combined with cocosbuilder, different screen adaptation Summary

Source: Internet
Author: User

This problem has been solved for several days. Here is a summary:

First, we agree to apply only one set of image resources to both iPhone 4 and iPhone 5 (the image can be displayed normally even on the ipad). Here we will make the background that needs to be displayed in full screen as the size of iPhone 5: 1136*640

I. cocosbuilder

1. Create a new scenario file and select iPhone 5 Landspcape to adjust the height to 1136*640:

 
 


Only one set of images is needed.

 


2. Set all nodes in the scenario as percentage coordinates:

 
 

 

 

2. coco2d-x

In our scenario, the size is 1136*960, and the ratio of the actual screen size to the design size to the height is used as the scaling factor. The Code is as follows:

 

CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize(); CCSize designSize = CCSizeMake(1136, 640); CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils(); std::vector<std::string> searchPaths; pFileUtils->setSearchPaths(searchPaths);  pDirector->setContentScaleFactor(screenSize.height/screenSize.height); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);     CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();    CCSize designSize = CCSizeMake(1136, 640);    CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();    std::vector<std::string> searchPaths;    pFileUtils->setSearchPaths(searchPaths);       pDirector->setContentScaleFactor(screenSize.height/screenSize.height);    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);   

The above method can be properly displayed in four simulators: iphone Retina (3.5-inch), iphone Retina (4-inch), ipad, and ipad Retina, and the location is correct.

Only when the ipad Retina image is enlarged will it be distorted.


 

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.