Hello there,
I try to create cocos2d-x project that support multi resolution for ipad, iphone. but it’s not working as expected.
For example : it shows images in ipad folder instead of iphone folder when i run it on iPhone Simulator.
this is my code in AppDelegate::applicationDidFinishLaunching
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(pEGLView);
// turn on display FPS
pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
// multi resolution support
pDirector->setOpenGLView(pEGLView);
CCSize frame_size = pEGLView->getFrameSize();
std::vector<std::string> res_dir_orders;
CCSize designSize = CCSizeMake(480, 320);
CCSize resourceSize;
if (2048 == frame_size.width || 2048 == frame_size.height)
{
res_dir_orders.push_back("ipadhd");
resourceSize = CCSizeMake(2048, 1536);
designSize = CCSizeMake(2048, 1536);
}
else if (1024 == frame_size.width || 1024 == frame_size.height)
{
res_dir_orders.push_back("ipad");
resourceSize = CCSizeMake(1024, 768);
designSize = CCSizeMake(1024, 768);
}
else if (1136 == frame_size.width || 1136 == frame_size.height)
{
res_dir_orders.push_back("iphonehd5");
resourceSize = CCSizeMake(1136, 640);
designSize = CCSizeMake(1136, 640);
}
else if (960 == frame_size.width || 960 == frame_size.height)
{
res_dir_orders.push_back("iphonehd");
resourceSize = CCSizeMake(960, 640);
designSize = CCSizeMake(960, 640);
}
else
{
res_dir_orders.push_back("iphone");
resourceSize = CCSizeMake(480, 320);
designSize = CCSizeMake(480, 320);
}
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(res_dir_orders);
pDirector->setContentScaleFactor(resourceSize.width / designSize.width);
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionFixedWidth);
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();
// run
pDirector->runWithScene(pScene);
What’s the engine version?
cocos2d.x.version: 2.2.3
Thanks for reading.