The first is the class structure:
As you can see, ccnode is almost the parent class of most classes processed in the game. It mainly has the following functions:
Virtual int getzorder (void) // obtain the node order
Virtual const ccpoint & getposition (void) // obtain the node location
Virtual void setposition (const ccpoint & var) // you can specify the node location.
Virtual ccarray * getchildren (void) // obtain all its subnodes
Virtual cccamera * getcamera (void) // obtain the corresponding camera
Virtual bool getisvisible (void) // determines whether the node is visible
Virtual void setisvisible (bool var) // you can specify node visibility.
Virtual const ccpoint & getanchorpoint (void) // obtain the node's anchor position
Virtual void setanchorpoint (const ccpoint & var) // you can specify the node's anchorpoint.
Virtual bool getisrunning (void) // judge whether the node is running
Virtual ccnode * getparent (void) // obtain the parent and node pointer
Virtual void setparent (ccnode * var) // you can specify the parent node of a node.
Virtual int gettag (void) // obtain the node tag
Virtual void settag (INT var) // sets the node tag
Char * description (void) // return the node description
Virtual void onenter () // callback function when entering the node
Virtual void onentertransitiondidfinish () // callback function after entering the node
Virtual void onexit () // callback function when the node is left
Virtual void addchild (ccnode * Child) // Add a node
Virtual void addchild (ccnode * child, int zorder) // Add nodes in sequence
Virtual void addchild (ccnode * child, int zorder, int tag) // Add nodes by sequence and tag
Void removefromparentandcleanup (bool cleanup) // Delete the current node in the parent node and clear the action and callback function
Virtual void removechild (ccnode * child, bool cleanup) // delete a node
Void removechildbytag (INT tag, bool cleanup) // delete a node by tag
Virtual void removeallchildrenwithcleanup (bool cleanup) // delete a node and clear the action and callback function
Ccnode * getchildbytag (INT tag) // get the node by tag
Virtual void reorderchild (ccnode * child, int zorder) // sorts data by order
Virtual void cleanup (void) // clear action
Virtual void draw (void) // draw yourself
Virtual void visit (void) // access the node
Ccaction * runaction (ccaction * Action) // run the action
Void stopallactions (void) // stop all actions
Void stopaction (ccaction * Action) // stop the action
Void stopactionbytag (INT tag) // stop the action by tag
Ccaction * getactionbytag (INT tag) // get the pointer of an action through tag
Unsigned int numberofrunningactions (void) // total number of running actions
Void schedule (sel_schedule selector) // defines a timer
Void schedule (sel_schedule selector, cctime interval) // defines a timer
Void unschedule (sel_schedule selector) // cancel a timer
Void unscheduleallselectors (void) // cancel all timers
Void resumeschedulerandactions (void) // restore timer and action
Void pauseschedulerandactions (void) // pause the timer and action
Static ccnode * node (void) // generate a node
Ccnode is the rendering chain of the cocos2d-x, write the game is basically dealing with him, the cocos2d-x can only render one ccscene at the same time, So ccscene is the rendering of the root node. When building a game, you generally add one or more cclayers to one scene, multiple ccsprite or ccmenu to one layer, and ccparticlesystem to ccsprite. In this way, a rendering tree is built, and the cocos2d-x goes through the tree to display the image on the screen.
The rendering of the coco2d-x is actually done by calling the visit () function: visit () This function calls the zorder of the child it contains <0 visit () function, and then calls draw () then, call the visit () function of zorder> = 0 of child. It is actually a depth-first algorithm. His child is ordered by zorder to ensure the correctness of rendering. Draw () is used to draw itself. In the ccsprite classes that do need to be drawn, draw () calls the OpenGL function to complete the painting function-maps a texture to a rectangle.
To customize some images, You can override the draw () function, but do not forget to call the draw () function of the parent class.
You can manage the network relationships. In fact, ccscene and cclayer are also ccnodes. it provides addition, deletion, and scaling of nodes. Each node has a camera and animation support. That is to say, each class derived from ccnode can be animated;
Introduction to the main class of cocos2d-X learning: node ccnode