Objective
Contact game development time is not long, has been writing Lua, writing Lua is certainly no development, at least you will write. Write the client, must see Cocos2d-x. From today onwards, officially began to cocos2d-x learning journey.
has been doing the development of C + +, turned to see Cocos2d-x, from the language, there are not many problems. For me, Cocos2d-x is a class library, similar to MFC, ATL and Qt, is a game class library, and I follow the Learning class library using the method to learn cocos2d-x. This article is called the basic concept, but still as a whole to say cocos2d-x this class library.
Basic architecture
In Cocos2d-x, the main concepts include the important concepts of director, Scene, Layer and Sprite, and the relationship between them is as follows.
This chart is very important, in the future development process, basically is based on this structure diagram to clarify the project structure. Cocos2d-x is such a management of different objects, and then composed a perfect, monthly water billions of projects, some things are the case.
Director (director)
Director controls the entire game, often with some scheduling control; in Cocos2d-x 3.x, director uses a singleton mode, which has only one instance during the entire game run. Director is the whole Cocos2d-x 3.x core, is the entire game navigator, in the game, generally by director to complete the following operation control:
Initialization of 1.OpenGL es;
2. Change of scene;
3. Suspension of the game, continued control;
4. Switching between world coordinates and GL coordinates;
5. Control of the nodes;
6. Save and invoke the saved game data;
7. Screen size acquisition, and so on.
Scene (Scene)
Scene scene is an essential element in Cocos2d-x 3.x, the game we need to build a different scene (at least one), the game level, plate switching is a scene between the switch. An important role of the scene is the role of process control, and we can control the free switching of different scenes in the game through a series of director methods. At the same time the scene is a layer container that contains all the game elements that need to be displayed. Typically, when we need to complete a scene, we create a scene subclass and implement the functionality we need in the subclass. For example, we can load game resources in the initialization of subclasses, add layers for scenes, start music playback, and so on.
Layer (layer)
Layer is the node subclass that handles the player event response. Unlike scenarios, layers usually contain content that is rendered directly on the screen and can accept user input events, including touch, keyboard input, and so on. We need to add sprite (sprites), text tags, or other game elements to the layer, and set the properties of the game elements, such as position, direction, and size, and set the action of the game elements. After we have designed the layers, just add the layers to the scene in order to be displayed.
Sprite (ELF)
The elves in the Cocos2d-x 3.x are similar to those in other game engines, which can move, rotate, scale, animate, and accept other transformations. The sprite in Cocos2d-x 3.x is made up of texure, frame, and animation, which is rendered by OpenGL ES. In the subsequent learning process, I will continue to summarize the various knowledge about Sprite.
Summarize
This article is just learning the beginning of the Cocos2d-x 3.x, I did not paste any code, as a novice, paste more code is futile, can not understand AH. Therefore, it is better to understand the overall structure of cocos2d-x, so that in the future study, the idea will be clearer. In any case, keep in mind the tree chart in the section of the infrastructure.
Cocos2d-x Learning entry threshold is very low, so that anyone can enter the world of cocos2d-x Development, how many developers to ensure their own advantages, in the follow-up learning process, we will not only work with cocos2d-x, but also know how cocos2d-x is to do the work.
Know it, but also know why.