Cocos2d-x Study Notes (1)-HelloWorld

Source: Internet
Author: User

I used to learn a lot of things, and later I mainly write WP7 mobile applications. Now I have the opportunity to get in touch with cocos2d-x, an excellent cross-platform game engine, but I have little experience in game development, if something is wrong, please forgive me. If you don't talk much about it, write the game directly! The previous sections mainly explain the knowledge points. Later, we will take the development of a shanzhai's cut fruit as an example to practice.
Cocos2d-x because it is directly moved from cocos2d, contains some Objective-C style classes, people familiar with OC development will be much more convenient, cocos2d-x engine comes with tests example detailed display of some of the effects of the engine, if you encounter some problems in the development process, or want to do some effect, you can refer to the source code in tests. Next, let's take a look at the simplest and most familiar example-Hello World!
First, let's look at the directory structure of hello world in the vs solution. Classes contains the game code file and Win32 contains the program file related to the development platform. If you are creating a new project, there will be a Resources folder that contains program resource files. You can place images and audio files. However, files in Classes are the key points that programmers need to pay attention.

The AppDelegate file is very important. At the beginning, we didn't need to perform some operations on it. There are a lot of code that you don't understand, but you should pay attention to the applicationDisFinishLanunching function, it can load game scenarios. You can use CCScene to specify the game scenario you want to enter. After the game is started, it will first enter this scenario. PDirector-> setDisplayFPS (true); you can set whether the simulator displays the number of frames of the game. The default value is 60 frames. You can also adjust the value by yourself. CCDirector is a very important class. It can be said that it is the overall manager of the game, big Boss, so to ensure that it can be accessed anywhere in the game, it is designed as a singleton model.
CCDirector has a MainLoop function that is used for automatic memory management and timer. Of course, it also contains other things that can be called by frame. Other functions will not be understood at the moment...
CCNode is the root class of the graphic object, and CCObject is the root class of the object. The specific things will be shown in the following study. CCScene is a game scenario and a carrier of interface controls. It is switched through CCDirector. CCLayer is a subset of CCScene and a container, however, its important function is to accept touch and gravity. CCSprite is the game genie! You can use a variety of 2d images as genie to perform various operations on them. In general, this is what we need to know at the beginning of learning cocos2d-x. Now you should try to see the code in Hello World. It is not very difficult if it is a little C ++ basics. Try to add your own images as the background to the game scene.
In HelloWorld. h must contain cocos2d. h so that you can include the library functions of the game engine. In order to add layers to the game, you must inherit the CCLayer, class HelloWorld: public cocos2d: CCLayer, init () class of the HelloWorld class () functions need to be called During scenario initialization, scene () is called During scenario loading, and menuCloseCallback is a callback function. In fact, there are so many things to talk about in HelloWorld. More things can be clearer only when we learn more.
Author: John_cdy

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.