Node class (CCNode)
The node class is the main class in the Cocos2D-X, inherited from CCObject, as shown in the inheritance relationship.
Any object that needs to be painted on the screen is a node class. The most common node classes include CCScene, CCLayer ),
CCSprite and CCMenu ).
The CCNode class provides the following functions:
<1> each node can contain subnodes. This example is provided later.
<2> the node contains periodic callback methods (Schedule, Unschedule, and so on ). The periodic callback method will be explained in detail later.
Skip this section.
<3> it can contain CCAction ).
CCNode can add additional functions for itself and its subnodes. Whether it is a CCAction running on CCNode or a set spin
The settings of the parent node can be passed to the child node for attributes such as angle and location conversion. This makes management easier in some game development. Ratio
For example, in some vertical version shooting games, the player-controlled leading aircraft must carry some sub-hosts. The sub-hosts must move along with the hosts, so we can
The sub-machine is set as the sub-node of the host. In this way, when setting the location, you only need to set the host location, which greatly reduces the need for programmers to handle
To improve the clarity and readability of the Code.
Because the CCNode class does not have its own texture, it does not actually see the effects of any node class on the screen, so there are two common CCNode class scenarios:
First caseA parent node is required to manage a batch of child nodes. In this case, an "invisible" child node can be set to manage the child nodes;Another situation
It is sometimes necessary to define an object displayed on the screen by yourself. At this time, let the newly defined class inherit from CCNode. A class inherits from CCNode
Class, which indicates that it has the followingFeatures:
<1> override the initialization method and periodic callback method.
<2> control the callback on the time line.
<3> rewrite the rendering method.