c++11 - How multi resolution support for all android devices in cocos2d-x 3.0 in landscape mode? -


i converting existing cocos2d game in android getting resolution problem there.in existing cocos game , using there 2 resources folder 1 ipad , 1 iphone.i want using these existing resources folder , can execute android game. please give me sample code work android resolution.

previously using below code ios

auto director = director::getinstance();

auto glview = director->getopenglview();

std::vector searchpaths;

size framesize = glview->getframesize();

if (framesize.height > 640) {     userdefault::getinstance()->setintegerforkey(device_type,ipad);      searchpath.push_back(largeresource.directory);      if(framesize.height>768)     {         userdefault::getinstance()->setboolforkey("retina",true);          director::getinstance()->setcontentscalefactor(0.5f);          userdefault::getinstance()->setboolforkey("ret", true);     }  } else {     userdefault::getinstance()->setintegerforkey(device_type,iphone);     searchpath.push_back(smallresource.directory);      if(director->getwinsize().width == 960)     {         userdefault::getinstance()->setboolforkey(ipod_5,false);      }     else     {         userdefault::getinstance()->setboolforkey(ipod_5,true);      } }  userdefault::getinstance()->flush(); 

fileutils::getinstance()->setsearchpaths(searchpath);

there’s many different screen sizes on android devices. example, below common values on phones (first value - resolution, second & third - aspect ratio):

480x800 - 3:5 or 0.6
480x854 - 0.5621
768x1280 - 3:5 or 0.6
720x1280 - 9:16 or 0.5625
1080x1920 - 9:16 or 0.5625
1440x2560 - 9:16 or 0.5625

and tablets:

2048x1536 (2048x1440) - 3:4 or 0.75 (0.7031)
1280x800 (1280x752) - 10:16 or 0.625 (0.5875)
1920x1200 (1920x1104) - 10:16 or 0.625 (0.575)
2560x1600 (2560x1504) - 10:16 or 0.625 (0.5875)
1024x600 (1024x552) - 0.5859 (0.539)

keep in mind there’s status bar on tablets. take resolution, , cocos application can’t see total device resolution, truncated (i showed in brackets). accordingly changes aspect ratio.
leads large selection of resolution values. therefore better group values aspect ratio devices. in case use method in appdelegate.cpp:

static size designresolutionsize = size(2560, 1600); // can choose designresolutionsize @ top of appdelegate 

in applicationdidfinishlaunching() method:

bool appdelegate::applicationdidfinishlaunching() {      …     auto glview = director->getopenglview();     if(!glview) {         glview = glviewimpl::create("my game");         director->setopenglview(glview);     }     glview->setdesignresolutionsize(designresolutionsize.width, designresolutionsize.height, resolutionpolicy::fixed_height);      std::vector <std::string> searchpaths;     singleton->setscreenrelation(glview->getframesize().height / glview->getframesize().width);     if (singleton->getscreenrelation() > 1)         singleton->setscreenrelation(1 / singleton->getscreenrelation()); // isn’t depend on screen orientation      if (singleton->getscreenrelation() <= 0.563) // phones 9:16 aspect ratio     {         searchpaths.push_back("phonebacks");     }     if ((singleton->getscreenrelation() > 0.563)&(singleton->getscreenrelation() <= 0.625)) // phones , tablets 10:16 , 3:5 aspect ratio     {         log("widetablet, %d", singleton->getscreenrelation());     }     if (singleton->getscreenrelation() > 0.625) // tablets 3:4 aspect ratio     {         searchpaths.push_back("tabletbacks");     }      cocos2d::fileutils::getinstance()->setsearchpaths(searchpaths); 

so, need background 3 different aspect ratios.
here important part – resolutionpolicy::fixed_height (or fixed_width) option. landscape screen orientation need fixed_height policy. means have fixed designresolution.height = 1600 pixels on devices, , variable width. example, on 720x1280 phone have background.width= 1600, , background.height = 1600/0.5625 = 2844 pixels. analogically use fixed_width portrait screen orientation.
method not perfect. similar values of aspect ratio backgrounds can cut several pixels, or vice versa, can seen @ edges of black stripes several pixels wide. method isn’t suitable moving backgrounds. fixed backgrounds gives picture , requires 3 resolutions of backgrounds.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -