Cocos2d x 3. X introduction tutorial (ii) : Node class

  • 2020-04-02 02:59:15
  • OfStack

A journey of a thousand miles begins with the first step

The following basic structure of cocos2d-x and some important classes were introduced in the previous article (link: #), and these important classes are introduced and analyzed separately. Let's go ~ ~ ~

The Node Node class

Node class is a very important class in cocos2d-x. It inherits from class Ref. About the Ref class, the Ref class is a memory management class.

How important is the Node class in cocos2d-x? Any object that needs to be drawn on the screen is a node class. The most commonly used node classes include Scene, Layer, Sprite, and Menu. The main functions of the Node class are as follows:

1. Each node can contain child nodes;
2. All nodes can contain scheduling methods (schedule, unschedule, etc.);
3. The node can contain actions;

Since the Node class does not have maps, the effect of any Node class cannot be seen on the screen. Node class is generally used in the following situations:

1. When a parent Node is needed to manage many children nodes, we can add a Node class as the parent Node to manage these children nodes;

2. Define our own Node class and make the Node class the parent class. We can override some virtual methods in the Node class to achieve the effect we need, such as:

1). Rewrite the initialization method and periodic callback method;
2). Rewrite the rendering method, etc.

The following is a summary of the classification of methods in the Node class, to give the overall impression that since cocos2d-x is open source, we can read its source code directly.

The function provided by the Node class

The functions provided by Node class mainly have the following functions:

1. Attributes of the node
2. Operation of nodes
3. Action related to Action
4. Timer-related schedule
5. Integrate the NodeRBGA class
6. Find the child node enumerateChildren
7. Render order zOrder
8. Coordinate conversion

In the future, when using Node class and its subclasses, it is good to be able to remember these functions. You can refer to the corresponding documents for the specific corresponding API functions. Corresponding to the use of API, I will explain through specific examples later.


Related articles: