Created
October 28, 2013 18:32
-
-
Save RodrigoAyala/7202103 to your computer and use it in GitHub Desktop.
Boilerplate code AppDelegate.cpp for Cocos2d-x games
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool AppDelegate::applicationDidFinishLaunching() { | |
CCSize designSize = CCSizeMake( 480,320); | |
CCSize resourceSize = CCSizeMake(480,320); | |
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 | |
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths); | |
if (screenSize.height > 768) | |
{ | |
resourceSize = CCSizeMake(2048,1536); | |
resDirOrders.push_back("resources-ipadhd"); | |
} | |
else if (screenSize.height > 640) | |
{ | |
resourceSize = CCSizeMake(1536,768); | |
resDirOrders.push_back("resources-ipad"); | |
}else if (screenSize.height > 480) | |
{ | |
resourceSize = CCSizeMake( 960,640); | |
resDirOrders.push_back("resources-iphonehd"); | |
} | |
else | |
{ | |
resDirOrders.push_back("resources-iphone"); | |
} | |
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders); | |
} | |
else if (platform == kTargetAndroid || platform == kTargetWindows) | |
{ | |
searchPaths.push_back("Published-Android"); // Resources/Published-iOS | |
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths); | |
if (screenSize.height > 960) | |
{ | |
resourceSize = CCSizeMake( 960,640); | |
resDirOrders.push_back("resources-large"); | |
} | |
else if (screenSize.height > 480) | |
{ | |
resourceSize = CCSizeMake( 720,480); | |
resDirOrders.push_back("resources-medium"); | |
} | |
else | |
{ | |
resourceSize = CCSizeMake( 568,320); | |
resDirOrders.push_back("resources-small"); | |
} | |
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders); | |
} | |
// initialize director | |
CCDirector* pDirector = CCDirector::sharedDirector(); | |
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); | |
pDirector->setOpenGLView(pEGLView); | |
pDirector->setContentScaleFactor(resourceSize.width/designSize.width); | |
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll); | |
// 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); | |
// create a scene. it's an autorelease object | |
CCScene *pScene = MainScene::scene(); | |
// run | |
pDirector->runWithScene(pScene); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment