Cocos2d-x node class (CCNode)

Source: Internet
Author: User

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.


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.