Skip to content

Instantly share code, notes, and snippets.

@takashi1975
Last active August 29, 2015 14:06
Show Gist options
  • Save takashi1975/c2e77fc43ef38c00aad2 to your computer and use it in GitHub Desktop.
Save takashi1975/c2e77fc43ef38c00aad2 to your computer and use it in GitHub Desktop.
Cocos2d-x v3.x マルチ解像度 例2
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 screenSize = glview->getFrameSize();
float scaleFactor = 1.0f;
Size designSize;
std::vector<std::string> resDirOrders;
switch (target)
{
case (Platform::OS_IPAD):
{
if (2048 == MAX(screenSize.width, screenSize.height))
{
resDirOrders.push_back("ipadhd");
scaleFactor = 4.0f;
}
else
{
resDirOrders.push_back("ipad");
scaleFactor = 2.0f;
}
designSize = Size(512, 384);
break;
}
case (Platform::OS_IPHONE):
{
if (1136 == MAX(screenSize.width, screenSize.height))
{
resDirOrders.push_back("iphonehd");
designSize = Size(568, 320);
scaleFactor = 1.0f;
}
else if (960.0f == MAX(screenSize.width, screenSize.height))
{
scaleFactor = 1.0f
resDirOrders.push_back("iphonehd");
designSize = Size(480.0f, 320.0f);
}
else
{
scaleFactor = 0.5f
resDirOrders.push_back("iphone");
designSize = Size(480.0f, 320.0f);
}
break;
}
default:
case (Platform::OS_ANDROID):
{
resDirOrders.push_back("iphonehd");
designSize = Size(480, 320);
scaleFactor = 1.0f;
break;
}
}
{
glview->setDesignResolutionSize(designSize.width,
designSize.height,
ResolutionPolicy::SHOW_ALL);
director->setContentScaleFactor(scaleFactor);
auto fileUtils = FileUtils::getInstance();
fileUtils->setSearchPaths(resDirOrders);
}
}
// 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

iPhone 6 / 6Plus を考慮していない ... 表示されない

考慮してみたもの
https://gist.github.com/takashi1975/b2b4f4efca95b82dd928

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