xcode4 - Auto get current resource for cocos2dx with app -


universal setting ipad, ipad retina, iphone, iphone4 , iphone5.

create folders "iphone" "iphone4" "iphone5" "ipad" "ipadhd" code intelligent load resource different folder. on iphone5, first scan "iphone5" folder, if resource don't exist. scan "iphone4" folder retina resource, if don't exist. scan "iphone" folder. so, resource must same filename in different folder.

in appdelegate.h add thost code:

typedef struct tagresource{ ccsize sizeinpixel; ccsize sizedesign; char directory[64]; }resource; static resource resiphone={ccsizemake(320, 480),ccsizemake(320, 480),"iphone"}; static resource resiphone4={ccsizemake(640, 960),ccsizemake(320, 480),"iphone4"}; static resource resiphone5={ccsizemake(640, 1136),ccsizemake(320, 568),"iphone5"}; static resource resipad={ccsizemake(768, 1024),ccsizemake(768, 1024),"ipad"}; static resource resipad3={ccsizemake(1536, 2048),ccsizemake(768, 1024),"ipadhd"}; 

in appdelegate.h @ bool appdelegate::applicationdidfinishlaunching() function:

/////retina resource resdevice[5]={resiphone5,resiphone4,resiphone,resipad3,resipad}; cceglview* peglview=cceglview::sharedopenglview(); ccsize framesize=peglview->getframesize(); resource resactual=resiphone; std::vector<std::string> respaths; (int i=0; i<5; i++) {     if (framesize.equals(resdevice[i].sizeinpixel)) {         resactual=resdevice[i];     }     float scalebitportrait=(float)framesize.height/resdevice[i].sizeinpixel.height;     float scalebitlandscape=(float)framesize.width/resdevice[i].sizeinpixel.height;     cclog("[res path] loop for: %s %f or %f",resdevice[i].directory,scalebitportrait,scalebitlandscape);     if (scalebitportrait==1 || scalebitportrait==2 || scalebitlandscape==1 || scalebitlandscape==2) {         respaths.push_back(resdevice[i].directory);     } }  (int i=0; i<respaths.size(); i++) {     cclog("[res path] load: %s",respaths[i].c_str()); }  ccfileutils::sharedfileutils()->setsearchpaths(respaths); pdirector->setcontentscalefactor(resactual.sizeinpixel.width/resactual.sizedesign.width); peglview->setdesignresolutionsize(resactual.sizedesign.width, resactual.sizedesign.height, kresolutionnoborder); 

Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -