Cocos2d-x Study Notes (17) (TestCpp source code analysis-1)

Source: Internet
Author: User
TestCpp source code based on Cocos2d-x2.1.3 version, part of the resources from the red child game programming road CSDN blog address blog. csdn. nethonghaierarticledetails8130947 expand the TestCpp project in VS2010. The TestCpp project contains 46 sample directories. In addition, the TestCpp project contains: (1) AppDelegate. hcpp: App for Program Control

TestCpp source code based on the Cocos2d-x2.1.3 version, part of the resources from the red child game programming path CSDN blog address http://blog.csdn.net/honghaier/article/details/8130947 in VS2010 expand TestCpp project, the following contains 46 sample directory, in addition to this, it also includes: (1) AppDelegate. h/cpp: App for Program Control

TestCpp source code based on Cocos2d-x2.1.3 version, part of the resources from the red child game programming road CSDN blog address http://blog.csdn.net/honghaier/article/details/8130947

Expand the TestCpp project in VS2010, and the following contains 46 sample directories. In addition, it also includes: (1) AppDelegate. h/cpp: program control class AppDelegate. (2) controller. h/cpp: The Example Scenario Management class TestController, used to display the menus of all examples. (3) testBasic. h/cpp: The base class TestScene of the sample scenario, which is used to return to the main interface scenario. (4) testResource. h: File resource name string definition header file (5) tests. h: Sample header file. (6) main. h/cpp: main function and header file. The following describes each file in detail.

(1) AppDelegate. h/cpp: the two files are program control class AppDelegate. The specific code is as follows:

// AppDelegate. h # ifndef _ APP_DELEGATE_H _ # define _ APP_DELEGATE_H _ # include "cocos2d. h "class AppDelegate: private cocos2d: CCApplication // AppDelegate class private inherits from CCApplication {public: AppDelegate (); // constructor virtual ~ AppDelegate (); // destructor virtual bool applicationDidFinishLaunching (); // This method will be called after the application is started. The default implementation includes the virtual void applicationDidEnterBackground () required after the game is started; // this method is called when the application enters the background. virtual void applicationWillEnterForeground (); // This method is paired with the previous method and called when the application returns to the foreground .}; # Endif // _ APP_DELEGATE_H _
This header file is the same as that described in study note 1. The following is an analysis of the cpp file.

# Include "AppDelegate. h "# include" cocos2d. h "# include" controller. h "// display the menu header file # include" SimpleAudioEngine. h "// background music playback header file USING_NS_CC; using namespace CocosDenshion; // declare the namespace to use SimpleAudioEngine. hAppDelegate: AppDelegate () // constructor {} AppDelegate ::~ AppDelegate () // destructor {// SimpleAudioEngine: end ();} bool AppDelegate: applicationDidFinishLaunching () // the startup program calls the function {// initialize director: initialize the game engine controller CCDirector to enable the game engine CCDirector * pDirector = CCDirector: sharedDirector (); pDirector-> setOpenGLView (CCEGLView: sharedOpenGLView ()); // set the scene display CCSize screenSize = CCEGLView: Export dopenglview ()-> getFrameSize (); // obtain the screen size CCSize designSize = CCSizeMake (480,320 ); // design the screen size CCFileUtils * pFileUtils = CCFileUtils: sharedFileUtils (); // if (screenSize. height> 320) // {CCSize resourceSize = CCSizeMake (960,640); std: vector
 
  
SearchPaths; searchPaths. push_back ("hd"); pFileUtils-> setSearchPaths (searchPaths); pctor ctor-> setContentScaleFactor (resourceSize. height/designSize. height); // set the screen matching scenario} CCEGLView: sharedOpenGLView ()-> setDesignResolutionSize (designSize. width, designSize. height, kResolutionNoBorder); // turn on display FPS pDirector-> setDisplayStats (true); // set enable FPS display // set FPS. the default value is 1.0/60 if you don't call this pDirector-> setAnimationInterval (1.0/60); // set the drawing interval, that is, the screen refresh frequency CCScene * pScene = CCScene:: create (); // create a scenario CCLayer * pLayer = new TestController (); // create a TestController layer for displaying the menu pLayer-> autorelease (); // use the recycle pool to release the layer's memory pScene-> addChild (pLayer); // Add the layer to the scene pDirector-> runWithScene (pScene ); // run the return true;} // This function will be called when the app is inactive. when comes a phone call, it's be invoked toovoid AppDelegate: applicationDidEnterBackground () // call this method When the program enters the background {CCDirector: shareddire()-> stopAnimation (); // pause SimpleAudioEngine: sharedEngine ()-> pauseBackgroundMusic (); // pause background music SimpleAudioEngine: sharedEngine ()-> pauseAllEffects (); // pause all events} // this function will be called when the app is active againvoid AppDelegate: applicationWillEnterForeground () // the program returns to the foreground using this method {CCDirector: shareddire () -> startAnimation (); // restart SimpleAudioEngine: sharedEngine ()-> resumeBackgroundMusic (); // reply to background music SimpleAudioEngine: sharedEngine ()-> resumeAllEffects (); // reply to all events}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.