Skip to content

Instantly share code, notes, and snippets.

@takashi1975
Created August 23, 2014 09:03
Show Gist options
  • Save takashi1975/a1360804d5e99bf0ecb1 to your computer and use it in GitHub Desktop.
Save takashi1975/a1360804d5e99bf0ecb1 to your computer and use it in GitHub Desktop.
Cocos2d-x v3 マルチ解像度
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
director->setOpenGLView(glview);
}
//マルチ解像度
{
auto target = Application::getInstance()->getTargetPlatform();
auto fileUtils = FileUtils::getInstance();
auto screenSize = glview->getFrameSize();
std::vector<std::string> resDirOrders;
switch (target)
{
case (Platform::OS_IPAD):
case (Platform::OS_IPHONE):
{
{
//iPad Retina
if ((2048 == screenSize.width) ||
(2048 == screenSize.height))
{
resDirOrders.push_back("ipadhd");
//glview->setDesignResolutionSize(2048, 1536, ResolutionPolicy::SHOW_ALL);
//glview->setDesignResolutionSize(1024, 768, ResolutionPolicy::SHOW_ALL);
glview->setDesignResolutionSize(512, 384, ResolutionPolicy::SHOW_ALL);
director->setContentScaleFactor(4.0f);
}
//iPad UnRetina
else if ((1024 == screenSize.width) ||
(1024 == screenSize.height))
{
resDirOrders.push_back("ipad");
//glview->setDesignResolutionSize(1024, 768, ResolutionPolicy::SHOW_ALL);
glview->setDesignResolutionSize(512, 384, ResolutionPolicy::SHOW_ALL);
director->setContentScaleFactor(2.0f);
}
//iPhone 4inch (Retina)
else if ((1136 == screenSize.width) ||
(1136 == screenSize.height))
{
resDirOrders.push_back("iphonehd");
//glview->setDesignResolutionSize(1156, 640, ResolutionPolicy::SHOW_ALL);
glview->setDesignResolutionSize(568, 320, ResolutionPolicy::SHOW_ALL);
//director->setContentScaleFactor(2.0f);
}
//iPhone 3.5inch (Retina)
else if ((960 == screenSize.width) ||
(960 == screenSize.height))
{
resDirOrders.push_back("iphonehd");
//glview->setDesignResolutionSize(960, 640, ResolutionPolicy::SHOW_ALL);
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::SHOW_ALL);
//director->setContentScaleFactor(2.0f);
}
//MARK: iPhone(非Retina) 切り捨て?
// else
// {
// resDirOrders.push_back("iphone");
//
// glview->setDesignResolutionSize(480, 320, ResolutionPolicy::SHOW_ALL);
// }
fileUtils->setSearchPaths(resDirOrders);
}
break;
}
default:
case (Platform::OS_ANDROID):
{
//480x320 固定
{
{
resDirOrders.push_back("iphonehd");
//glview->setDesignResolutionSize(960, 640, ResolutionPolicy::SHOW_ALL);
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::SHOW_ALL);
//director->setContentScaleFactor(2.0f);
}
fileUtils->setSearchPaths(resDirOrders);
}
break;
}
}
}
// turn on display FPS
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
// create a scene. it's an autorelease object
auto scene = HelloWorld::createScene();
// run
director->runWithScene(scene);
return true;
}
@takashi1975
Copy link
Author

Cocos2d-x v3 C++ Tutorial 4 – Multi Resolution Support
https://www.youtube.com/watch?v=CH9Ct4R0nBM

... を自分用に改造... iOS/Android(Androidは480x320固定)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment