[Cocos2d-x] --- CCNode class details

Source: Internet
Author: User

1 CCNode is a very important class in cocos2d-x, CCNode is the parent class of scene, layer, menu, Genie, etc. While we are using cocos2d-x, the most contact is the scene, layer, menu, Genie and so on. Therefore, it is necessary to understand the CCNode class first.

 

2 CCObject class is the base class of all objects in the cocos2d-x, CCObject encapsulates the reference count and automatic release function of the object, below is the class diagram

 

 

3 because the scenario, layer, Genie, and menu are child classes of CCNode, some methods come from CCNode when using them. The following describes common methods of CCNode.

[Cpp]
// Initialize CCNode
Bool init ();
 
// Generate a CCNode object
CCNode * create (void );
 
// Obtain the description string for debugging
Const char * description (void );
 
// Set the node z-axis sequence. When multiple nodes are displayed on the z-axis, the engine determines the size of their Z-axes.
Void setZOrder (int zOrder );
Void _ setZOrder (int z );
// Obtain the node z-axis Sequence
Int getZOrder ();
 
// Sets the OpenGL Z axis vertex.
Void setVertexZ (float vertexZ );
// Obtain the x-axis vertex of OpenGL
Float getVertexZ ();
 
// Set the node X-axis proportional factor
Void setScaleX (float fScaleX );
// Obtain the node X-axis proportional factor
Float getScaleX ();
 
// Set the node Y-axis proportional factor
Void setScaleY (float fScaleY );
// Obtain the node Y-axis proportional factor
Float getScaleY ();
 
// Set the node proportional factor and the X and Y axes
Void setScale (float scale );
// Obtain the node proportional factor, which must be equal to the X axis and Y axis proportional factor.
Float getScale ();
 
// Set the coordinates of the node (x, y) in OpenGL.
Void setPosition (const CCPoint & position );
// Obtain the coordinates of the node (x, y) in OpenGL.
Const CCPoint & getPosition ();
 
// Set the coordinates of the node (x, y) in OpenGL.
Void setPosition (float x, float y );
// Obtain the coordinates of the node (x, y) in OpenGL.
Void getPosition (float * x, float * y );
 
// Set the X coordinate of the node in OpenGL
Void setPositionX (float x );
// Obtain the X coordinate of the node in OpenGL
Float getPositionX (void );
// Set Y coordinates of nodes in OpenGL
Void setPositionY (float y );
// Obtain the Y coordinate of the node in OpenGL
Float getPositionY (void );
 
// Set the skew angle of the X axis
Void setSkewX (float fSkewX );
// Obtain the skew angle of the X axis
Float getSkewX ();
 
// Set the tilt angle of the Y axis
Void setSkewY (float fSkewY );
// Obtain the tilt angle of the Y axis
Float getSkewY ();
 
// Set the node anchor position
Void setAnchorPoint (const CCPoint & anchorPoint );
// Obtain the node anchor position
Const CCPoint & getAnchorPoint ();
 
// Set the node size
Void setContentSize (const CCSize & contentSize );
// Obtain the node size
Const CCSize & getContentSize ();
 
// Set whether the node is visible
Void setVisible (bool visible );
// Obtain whether the node is visible
Bool isVisible ();
 
// Set the Rotation Angle of the node
Void setRotation (float fRotation );
// Obtain the Rotation Angle of a node
Float getRotation ();
 
// ZOrder when multiple nodes are displayed on the Z axis, the engine will decide the size of the Z axis based on their Z axis.
// Add the subnode zOrder. The default value is 0.
Void addChild (CCNode * child );
// Add a subnode
Void addChild (CCNode * child, int zOrder );
// Add a subnode to specify the node zOrder and node tag
Void addChild (CCNode * child, int zOrder, int tag );
 
// Get the node by tag Name
CCNode * getChildByTag (int tag );
// Obtain all child nodes
CCArray * getChildren ();
// Obtain the number of subnodes
Unsigned int getChildrenCount (void );
 
// Set the parent node of the child node
Void setParent (CCNode * parent );
// Obtain the parent node of the child node
CCNode * getParent ();
 
// Delete the current child node from the parent node
Void removeFromParent ();
// Delete the current child node from the parent node. If Cleanup is set to true, all actions and callback functions of the current node will be deleted.
Void removeFromParentAndCleanup (bool cleanup );
// Delete the current child node from the parent node. If Cleanup is set to true, all actions of the current child node will be deleted.
Void removeChild (CCNode * child );
// Delete the current child node from the parent node and specify Cleanup
Void removeChild (CCNode * child, bool cleanup );
// Remove a node by tag Name
Void removeChildByTag (int tag );
// Remove a node by tag Name and specify Cleanup
Void removeChildByTag (int tag, bool cleanup );
// Remove all child nodes
Void removeAllChildren ();
// Remove all child nodes and specify Cleanup
Void removeAllChildrenWithCleanup (bool cleanup );
 
// Reset the zOrder of the node
Void reorderChild (CCNode * child, int zOrder );
 
// Sort all subnodes again
Void sortAllChildren ();
 
// Obtain the node tag Name
Int getTag ();
// Set the node tag Name
Void setTag (int nTag );
 
// Get the CCCamera camera cocos2d-x of the node is drawn in 3D mode 2D Effect
CCCamera * getCamera ();
 
// Determine whether the current node is running
Bool isRunning ();
 
// The callback event when the node starts to enter the stage
Void onEnter ();
// The callback event when the node enters the stage
Void onEnterTransitionDidFinish ();
// Callback event when the node leaves the stage
Void onExit ();
 
// Stop all running actions and callback Functions
Void cleanup (void );
 
// Draw a node
Void draw (void );
 
// Recursive visit subnode re-painting
Void visit (void );
 
// Return the rectangle of the Node object (composed of coordinate width and height)
CCRect boundingBox (void );
 
// Sets the CCActionManager object to be used by all actions
Void setActionManager (CCActionManager * actionManager );
// Obtain the CCActionManger used by all actions
CCActionManager * getActionManager ();
 
// Execute the action
CCAction * runAction (CCAction * action );
// Stop the action
StopAction (CCAction * action );
 
 
// Stop all actions
Void stopAllActions (void );
 
// Obtain the action by tag Name
CCAction * getActionByTag (int tag );
 
// Obtain the number of running actions
Unsigned int numberOfRunningActions (void );
 
// Define a timer
Void schedule (SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay );
// Define a timer
Void schedule (SEL_SCHEDULE selector, float interval );
 
// Cancel a timer
Void unschedule (SEL_SCHEDULE selector );
// Cancel all timers
Void unscheduleAllSelectors (void );
 
// Pause all timer and action
Void pauseSchedulerAndActions (void );
// Restore all timer and action
Void resumeSchedulerAndActions (void );

// Initialize CCNode
Bool init ();

// Generate a CCNode object
CCNode * create (void );

// Obtain the description string for debugging
Const char * description (void );

// Set the node z-axis sequence. When multiple nodes are displayed on the z-axis, the engine determines the size of their Z-axes.
Void setZOrder (int zOrder );
Void _ setZOrder (int z );
// Obtain the node z-axis Sequence
Int getZOrder ();

// Sets the OpenGL Z axis vertex.
Void setVertexZ (float vertexZ );
// Obtain the x-axis vertex of OpenGL
Float getVertexZ ();

// Set the node X-axis proportional factor
Void setScaleX (float fScaleX );
// Obtain the node X-axis proportional factor
Float getScaleX ();

// Set the node Y-axis proportional factor
Void setScaleY (float fScaleY );
// Obtain the node Y-axis proportional factor
Float getScaleY ();

// Set the node proportional factor and the X and Y axes
Void setScale (float scale );
// Obtain the node proportional factor, which must be equal to the X axis and Y axis proportional factor.
Float getScale ();

// Set the coordinates of the node (x, y) in OpenGL.
Void setPosition (const CCPoint & position );
// Obtain the coordinates of the node (x, y) in OpenGL.
Const CCPoint & getPosition ();

// Set the coordinates of the node (x, y) in OpenGL.
Void setPosition (float x, float y );
// Obtain the coordinates of the node (x, y) in OpenGL.
Void getPosition (float * x, float * y );

// Set the X coordinate of the node in OpenGL
Void setPositionX (float x );
// Obtain the X coordinate of the node in OpenGL
Float getPositionX (void );
// Set Y coordinates of nodes in OpenGL
Void setPositionY (float y );
// Obtain the Y coordinate of the node in OpenGL
Float getPositionY (void );

// Set the skew angle of the X axis
Void setSkewX (float fSkewX );
// Obtain the skew angle of the X axis
Float getSkewX ();

// Set the tilt angle of the Y axis
Void setSkewY (float fSkewY );
// Obtain the tilt angle of the Y axis
Float getSkewY ();

// Set the node anchor position
Void setAnchorPoint (const CCPoint & anchorPoint );
// Obtain the node anchor position
Const CCPoint & getAnchorPoint ();

// Set the node size
Void setContentSize (const CCSize & contentSize );
// Obtain the node size
Const CCSize & getContentSize ();

// Set whether the node is visible
Void setVisible (bool visible );
// Obtain whether the node is visible
Bool isVisible ();

// Set the Rotation Angle of the node
Void setRotation (float fRotation );
// Obtain the Rotation Angle of a node
Float getRotation ();

// ZOrder when multiple nodes are displayed on the Z axis, the engine will decide the size of the Z axis based on their Z axis.
// Add the subnode zOrder. The default value is 0.
Void addChild (CCNode * child );
// Add a subnode
Void addChild (CCNode * child, int zOrder );
// Add a subnode to specify the node zOrder and node tag
Void addChild (CCNode * child, int zOrder, int tag );

// Get the node by tag Name
CCNode * getChildByTag (int tag );
// Obtain all child nodes
CCArray * getChildren ();
// Obtain the number of subnodes
Unsigned int getChildrenCount (void );

// Set the parent node of the child node
Void setParent (CCNode * parent );
// Obtain the parent node of the child node
CCNode * getParent ();

// Delete the current child node from the parent node
Void removeFromParent ();
// Delete the current child node from the parent node. If Cleanup is set to true, all actions and callback functions of the current node will be deleted.
Void removeFromParentAndCleanup (bool cleanup );
// Delete the current child node from the parent node. If Cleanup is set to true, all actions of the current child node will be deleted.
Void removeChild (CCNode * child );
// Delete the current child node from the parent node and specify Cleanup
Void removeChild (CCNode * child, bool cleanup );
// Remove a node by tag Name
Void removeChildByTag (int tag );
// Remove a node by tag Name and specify Cleanup
Void removeChildByTag (int tag, bool cleanup );
// Remove all child nodes
Void removeAllChildren ();
// Remove all child nodes and specify Cleanup
Void removeAllChildrenWithCleanup (bool cleanup );

// Reset the zOrder of the node
Void reorderChild (CCNode * child, int zOrder );

// Sort all subnodes again
Void sortAllChildren ();

// Obtain the node tag Name
Int getTag ();
// Set the node tag Name
Void setTag (int nTag );

// Get the CCCamera camera cocos2d-x of the node is drawn in 3D mode 2D Effect
CCCamera * getCamera ();

// Determine whether the current node is running
Bool isRunning ();

// The callback event when the node starts to enter the stage
Void onEnter ();
// The callback event when the node enters the stage
Void onEnterTransitionDidFinish ();
// Callback event when the node leaves the stage
Void onExit ();

// Stop all running actions and callback Functions
Void cleanup (void );

// Draw a node
Void draw (void );

// Recursive visit subnode re-painting
Void visit (void );

// Return the rectangle of the Node object (composed of coordinate width and height)
CCRect boundingBox (void );

// Sets the CCActionManager object to be used by all actions
Void setActionManager (CCActionManager * actionManager );
// Obtain the CCActionManger used by all actions
CCActionManager * getActionManager ();

// Execute the action
CCAction * runAction (CCAction * action );
// Stop the action
StopAction (CCAction * action );


// Stop all actions
Void stopAllActions (void );

// Obtain the action by tag Name
CCAction * getActionByTag (int tag );

// Obtain the number of running actions
Unsigned int numberOfRunningActions (void );

// Define a timer
Void schedule (SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay );
// Define a timer
Void schedule (SEL_SCHEDULE selector, float interval );

// Cancel a timer
Void unschedule (SEL_SCHEDULE selector );
// Cancel all timers
Void unscheduleAllSelectors (void );

// Pause all timer and action
Void pauseSchedulerAndActions (void );
// Restore all timer and action
Void resumeSchedulerAndActions (void );


 

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.