Skip to content

Instantly share code, notes, and snippets.

@tadamatu
Last active December 15, 2015 04:29
Show Gist options
  • Save tadamatu/5201880 to your computer and use it in GitHub Desktop.
Save tadamatu/5201880 to your computer and use it in GitHub Desktop.
cocos2dxの解像度対応
//画面解像度対応
// 480x320ベースで実装を行う(iPhone 4inchのみ568x320)
// 画像は以下のそれぞれのフォルダより取得
// @2x Resources/Published-iOS/resources-iphonehd
// 通常 Resources/Published-iOS/resources-iphone
//※AppDelegate::applicationDidFinishLaunching{} に実装する
// this->changeDisplayHd();
void AppDelegate::changeDisplayHd() {
CCDirector *pDirector = CCDirector::sharedDirector();
CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
std::vector<std::string> searchPaths;
std::vector<std::string> resDirOrders;
TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform();
if (platform == kTargetIphone || platform == kTargetIpad){
searchPaths.push_back("Published-iOS"); // Resources/Published-iOS
if (screenSize.height > 480){
//Retainaによる幅調整
resDirOrders.push_back("resources-iphonehd"); //Resources/Published-iOS/resources-iphonehd
pDirector->setContentScaleFactor(2.f); //2倍のスケールサイズ
if (screenSize.width==1136.0 || screenSize.height==1136.0 ) {
//4-inch
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(568, 320, kResolutionShowAll);
} else {
//3.5-inch
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionShowAll);
}
}else{
//通常サイズ
resDirOrders.push_back("resources-iphone"); //Resources/Published-iOS/resources-iphone
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionShowAll);
}
}else{
// iOS以外(Androidなど)
searchPaths.push_back("Published-iOS"); // Resources/Published-iOS
resDirOrders.push_back("resources-iphone");
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionExactFit);
}
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);
}
@tadamatu
Copy link
Author

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