Skip to content

Instantly share code, notes, and snippets.

@takashi1975
Last active August 29, 2015 14:24
Show Gist options
  • Save takashi1975/b2b4f4efca95b82dd928 to your computer and use it in GitHub Desktop.
Save takashi1975/b2b4f4efca95b82dd928 to your computer and use it in GitHub Desktop.
Cocos2d-x v3.x マルチ解像度 例3 (iPhone 6/6Plus 考慮)
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
director->setOpenGLView(glview);
}
//マルチ解像度
{
//端末の画面
const auto screenSize = glview->getFrameSize();
const auto screenMaxLen = MAX(screenSize.width, screenSize.height);
//画面の向き(縦かどうか)
const auto isPortrait = (screenSize.width < screenSize.height);
//設定項目
auto designSize = Size::ZERO;
auto scaleFactor = 1.0f;
std::vector<std::string> resDirOrders;
//ゲーム画面サイズ
const auto target = Application::getInstance()->getTargetPlatform();
switch (target)
{
case (Platform::OS_IPAD):
{
//iPad専用の画面で考える
designSize = (isPortrait) ? (Size(768.0f, 1024.0f)) : (Size(1024.0f, 768.0f));
break;
}
case (Platform::OS_IPHONE):
{
auto length = 960.0f;
//3.5inch
if (960.0f >= screenMaxLen)
{
length = 960.0f;
}
//4.0inch, 4.7inch, 5.5inch
else if (1136.0f <= screenMaxLen)
{
length = 1136.0f;
}
{
//ゲーム画面サイズ
designSize = (isPortrait) ? (Size(640.0f, length)) : (Size(length, 640.0f));
}
break;
}
default:
case (Platform::OS_ANDROID):
{
//Android 固定のサイズで考える(余白ありきで考える)
designSize = (isPortrait) ? (Size(640.0f, 960.0f)) : (Size(960.0f, 640.0f));
break;
}
}
//リソースの決定
{
const auto scale = (isPortrait) ? (screenSize.width / designSize.width) : (screenSize.height / designSize.height);
if (scale >= 2.0f)
{
//iPad Retina
resDirOrders.push_back("ipadhd");
scaleFactor = 2.0f;
}
else
{
//iPad 非Retina(iPhone Retina)
resDirOrders.push_back("ipad");
scaleFactor = 1.0f;
}
//scaleFactor = scale;
}
//解像度設定
{
//全体を表示(見切れなし)
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

エミュレータで確認していると、
ふと、cocos2d-x fps のデバッグ表示の文字のサイズが端末ごとで異なるので、
「まさかラベルのサイズが!?」...とは思ったが、
Label::createWithSystemFont で作成した Label はどれも同じ感じで表示できた。

これでやってみようと思います。^^;

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