Cocos2d-x game engine development notes (1) helloworld

Source: Internet
Author: User

 

Original article. For more information, see http://blog.csdn.net/zhy_cheng/article/details/8266803.

It's another helloworld. In my impression, there are helloworld of C/C ++, Hellworld of C #, helloworld of Java, and helloworld of Android, it is also a new knowledge of total, but this time helloworld is my favorite helloworld, because it was developed by the game helloworld, and I like playing games very much, of course Dota is the favorite.

 

Nothing to say, Cocos2d-x is a cross-platform game engine, cross platform is iOS, Android, BlackBerry playbook, bada, marmalade, windows, Linux. The development language is C ++. This language can ensure that the game runs fast enough. Recently, after reading "C ++ primer", I am now trying to test it, for my c ++ Development notes, see C ++
Primer study notes.

 

 

Here, I will continue to write down my study notes, so that I can consolidate my learning knowledge, and provide reference and source code for future programming. Finally, it is convenient for everyone to learn and avoid detours, learn together.

 

I think game development is the trend of the times. You can use the game development method to develop applications. In this way, the applications will be cool. Ghohst team developed an electronic recipe program with Cocos2d-x, really cool, video address: http://v.youku.com/v_show/id_xndq3md?nju2.html. So it is really necessary to learn about this game engine.

 

My development environments are win7 and vs2010.

 

Download 2.0.4 (2012-11-02) for the first time. Download and decompress the package to any directory with the following files:

Since my installation is vs2010, double-click the cocos2d-win32.vc2010.sln, if vs is another version, click the SLN file of another version, here there are vs2008 and vs2012. After importing the project, right-click solution and click Generate solution. compile the project for a while. After the compilation is successful, right-click the hellocpp project in the project and click debug -----> Start a new instance. When this occurs, the environment is set up:

 

There are other projects in this project, you can try testcpp Project, which is a comprehensive test of the Cocos2d-x, we can also look at the Cocos2d-x can achieve those functions.

 

In the face of vs2010 install Cocos2d-x Installation Template, click the cocos2d-2.0-x-2.0.4 file under the install-templates-msvc.bat folder, will give vs2010 install Cocos2d-x development template. Right-click solution, click Add ---> new project, select Cocos2d-win32 application, enter the name mytest and location, and click OK. Next, select default and click Finish. Create a mytest. Win32 project under our project and run the project. The following interface is displayed:

 

 

Let's take a look at the Cocos2d-x template to generate a sample project for us.

 

 

Put the header file in the include folder, put the resource file in the resource folder, put the source file in the source folder, and an external dependency, which is a reference to other files in the Cocos2d-x. The code in Main. cpp is as follows:

Appdelegate app; // create an application instance cceglview * eglview = cceglview: Export dopenglview (); eglview-> setframesize (480,320); // set the page size int ret = ccapplication :: sharedapplication ()-> Run (); // run the application message loop

In the appdelegate class, there are three virtual functions.

Virtual bool applicationdidfinishlaunching (); // call this method after the application completes loading.

Virtual void applicationdidenterbackground (); // The application calls this method in the background.

Virtual void applicationwillenterforeground (); // this method is called when the application enters the foreground.

 

In the applicationdidfinishlaunching method, initialize the Director object, set FPS, and run the scenario.

In the applicationdidenterbackground method, disable the animation and stop the background music.

In the applicationwillenterforeground method, start the animation and continue the background music.

 

The helloworld class is a set. It inherits cclayer. In the helloworld class, there are three methods.

virtual bool init();  static cocos2d::CCScene* scene();void menuCloseCallback(CCObject* pSender);

The init method initializes some class content, a menu, a character, and a background in the set. The generation of these class content will continue in the following blog.

The scene method uses this set to generate a scenario.

Menuclosecallback method response user click menu

 

Well, I'm done. This blog post focuses on building a development environment and introducing how the helloworld project runs. Welcome to the next blog.

 

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.