--------------------------CCApllication类-----------------------------
cocos2dx肯定会从CCApplication是派生出一个类,一般来说,这个派生类会重写下面3个虚函数
- //初始化scene与CCDirector
- virtual bool applicationDidFinishLaunching();
- //窗口恢复时候调用SIZE_RESTORED
- virtual void applicationWillEnterForeground();
- //窗口最小化时候调用SIZE_MINIMIZED
- virtual void applicationDidEnterBackground();
示范代码:
- bool AppDelegate::applicationDidFinishLaunching()
- {
- // initialize director
- CCDirector *pDirector = CCDirector::sharedDirector();
- pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
- CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
- CCSize designSize = CCSizeMake(480, 320);
- if (screenSize.height > 320)
- {
- CCSize resourceSize = CCSizeMake(960, 640);
- CCFileUtils::sharedFileUtils()->setResourceDirectory("hd");
- pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
- }
- CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
- // 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);
- CCScene * pScene = CCScene::create();
- CCLayer * pLayer = new TestController();
- pLayer->autorelease();
- pScene->addChild(pLayer);
- pDirector->runWithScene(pScene);
- return true;
- }
- // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
- void AppDelegate::applicationDidEnterBackground()
- {
- CCDirector::sharedDirector()->stopAnimation();
- SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
- SimpleAudioEngine::sharedEngine()->pauseAllEffects();
- }
- // this function will be called when the app is active again
- void AppDelegate::applicationWillEnterForeground()
- {
- CCDirector::sharedDirector()->startAnimation();
- SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
- SimpleAudioEngine::sharedEngine()->resumeAllEffects();
- }