在创建完了工程之后,我们可以看到AppDelegate这个文件,我们打开看下这里面有什么:

AppDelegate::AppDelegate() { //1,构造AppDelegate

}

AppDelegate::~AppDelegate() 
{
}

bool AppDelegate::applicationDidFinishLaunching() {//3,在2初始化完之后进入,结束初始化appDelegate
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);
	
    // 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();
    GameDemoManager * pLayer = new GameDemoManager();
	pLayer->initGame();
    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() {//4,当手机处于后台运行的时候,进入该处
    CCDirector::sharedDirector()->stopAnimation();

    // if you use SimpleAudioEngine, it must be pause
    // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() { /,2,构造完了AppDelegate之后进入初始化application
    CCDirector::sharedDirector()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}



从上面分析:

AppDelegate其实就是整个程序的入口,它的初始化步骤就是上面的1-3,4则是在手机后台运行该程序时所调用的