Cocos2d-x adaptive android different resolution, using multiple sets of resources

Source: Internet
Author: User

Although the cocos2d-x comes with three modes to adapt to the screen, but there are still some problems, will produce Black edge, so we still need multiple sets of resources to adapt to the screen. Here I have selected four resolutions:, and. I have created four folders in the resource Directory and placed multiple sets of background images. Just add the following function calls to AppDelegate. [Cpp] void AppDelegate: ScreenAdaptive () {CCSize szFrame = CCEGLView: Export dopenglview ()-> getFrameSize (); float Proportion = szFrame. width/szFrame. height; const int num = 4; float diff [num] = {fabs (Proportion-(9.0/16), fabs (Proportion-(3.0/5 )), fabs (Proportion-(2.0/3), fabs (Proportion-(3.0/4)}; int yy =-1; for (int I = 0; I <num; I ++) if (diff [I]>-0.000001) & (diff [I] <0.000001) {yy = I; break ;} if (yy =-1) {int min = diff [0]; yy = 0; for (int I = 1; I <num; I ++) if (diff [I] <min) {min = diff [I]; yy = I ;}} switch (yy) {case 0: {std :: vector <string> searchPaths; searchPaths. push_back ("9x16"); CCFileUtils: sharedFileUtils ()-> setSearchPaths (searchPaths); CCEGLView: Export dopenglview ()-> Export (648,1152, kResolutionShowAll); break ;} case 1: {std: vector <string> searchPaths; searchPaths. push_back ("3x5"); CCFileUtils: sharedFileUtils ()-> setSearchPaths (searchPaths); CCEGLView: Export dopenglview ()-> Export (, kResolutionShowAll); break ;} case 2: {std: vector <string> searchPaths; searchPaths. push_back ("2x3"); CCFileUtils: sharedFileUtils ()-> setSearchPaths (searchPaths); CCEGLView: Export dopenglview ()-> Export (640,960, kResolutionShowAll); break ;} case 3: {std: vector <string> searchPaths; searchPaths. push_back ("3x4"); CCFileUtils: sharedFileUtils ()-> setSearchPaths (searchPaths); CCEGLView: Export dopenglview ()-> setDesignResolutionSize (624,832, kResolutionShowAll ); break ;}} here is a brief introduction to setSearchPaths. In the latest version, setResourceDirectory is no longer available and is replaced by setSearchPaths. The following is a description of setSearchPaths: [cpp]/*** Sets the array of search paths. ** You can use this array to modify the search path of the resources. * If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array. ** @ note This method cocould access relative path and absolute path. * If the relative path was passed to the vector, CCFileUtils will add the default resource directory before the relative path. * For instance: * On Android, the default resource root path is "assets /". * If "/mnt/sdcard/" and "resources-large" were set to the search paths vector, * "resources-large" will be converted to "assets/resources-large" since it was a relative path. ** @ param searchPaths The array contains search paths. * @ see fullPathForFilename (const char *) * @ since v2.1 */[cpp] // set searching paths to "/mnt/sd/example" and "/data/org. cocos2dx. example "vector <string> searchPaths; searchPaths. push_back ("/mnt/sd/example"); searchPaths. push_back ("/data/org. cocos2dx. example "); CCFileUtils: setSearchPaths (searchPaths); // engine will find" 1.png" in/mnt/sd/example, if there it is not found, then engine will find "1.png" in/data/org. cocos2dx. example // if not found, engine will find "1.png" in Resources/(this path is platform dependent) [cpp] CCSprite * pSprite = CCSprite

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.