CCDriector is the core of the coco2s-x, used to create and control the display of the main screen, while controlling the scene display time and display mode. Generally, there is only one CCDirector in the game.
Role :? Initialize the OpenGL session.
? Set parameters and methods of OpenGL.
? Access and change the configuration details of the scenario and access Cocos2D-x.
? Access view.
? Set projection and orientation
Call method: CCDirector: shareddire()-> function name
Instance: Open the instance in the previous section and find and open AppDelegate. cpp. The code is roughly as follows:
Bool AppDelegate: applicationDidFinishLaunching () {// initialize director initialize CCDirector * pDirector = CCDirector: shareddire ();
// Set the openGl view pDirector-> setOpenGLView (CCEGLView: sharedOpenGLView (); // turn on display FPS whether to display the time per frame pDirector-> setDisplayStats (true ); // set FPS. the default value is 1.0/60 if you don't call this sets the time of each frame pDirector-> setAnimationInterval (1.0/60); // create a scene. it's an autorelease object creation scenario CCScene * pScene = HelloWorld: scene (); // run the scenario pDirector-> runWithScene (pScene); return true ;}
// The Work of the director when the game enters the background or returns from the background
// This function will be called when the app is inactive. When comes a phone call,it's be invoked toovoid AppDelegate::applicationDidEnterBackground(){ CCDirector::sharedDirector()->stopAnimation(); SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();}
// this function will be called when the app is active againvoid AppDelegate::applicationWillEnterForeground(){ CCDirector::sharedDirector()->startAnimation(); SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();}