Cocos2D-x 3.5 engine resolution-Node)
# Ifndef _ CCNODE_H __
# Define _ CCNODE_H __
# Include "base/ccMacros. h"
# Include "base/CCVector. h"
# Include "base/CCProtocols. h"
# Include "base/CCScriptSupport. h"
# Include "math/CCAffineTransform. h"
# Include "math/CCMath. h"
NS_CC_BEGIN
Class GridBase;
Class Touch;
Class Action;
Class LabelProtocol;
Class Scheduler;
Class ActionManager;
Class Component;
Class ComponentContainer;
Class EventDispatcher;
Class Scene;
Class Renderer;
Class Director;
Class GLProgram;
Class GLProgramState;
# If CC_USE_PHYSICS
Class PhysicsBody;
# Endif
/**
* @ Addtogroup _ 2d
*@{
*/
Enum {
KNodeOnEnter,
KNodeOnExit,
KNodeOnEnterTransitionDidFinish,
KNodeOnExitTransitionDidStart,
KNodeOnCleanup
};
Bool CC_DLL nodeComparisonLess (Node *N1, Node *N2);
Class EventListener;
A simple node is the basic element of a scene graph. The element of a scene must be a Node object or a subclass object of a node. Common node objects include scene, layer, Genie, menu, and label.
The main features of a node are:
-Other node objects can be included (using addChild, getChildByTag, and removeChild)
-You can use the timer to use the callback function (schedule, unschedule)
-RunAction (stopAction)
The subclass of the node means:
Reload the inti function to initialize resources and call the callback function when loading resources.
Create a callback function to process events
Reload draw to render nodes
Node features:
Location (default (0, 0 )),
Zoom (default x = 0, y = 0, that is, no zoom in the x and y directions)
Rotation (angle, orientation, 0 by default, that is, no rotation)
Anchor (0, 0 by default ))
Size (width and height)
Visible (visible by default)
Limitations:
A node is an empty object. If you want to display it on the screen, you need to use the Wizard to replace or set the Child class of the node and reload the draw function.
Class CC_DLL Node: public Ref // public inheritance Ref, that is, each Node object can be referenced and counted.
{
Public:
Static const int INVALID_TAG =-1;
Enum {
FLAGS_TRANSFORM_DIRTY = (1 <0 ),
FLAGS_CONTENT_SIZE_DIRTY = (1 <1 ),
FLAGS_RENDER_AS_3D = (1 <3 ),
FLAGS_DIRTY_MASK = (FLAGS_TRANSFORM_DIRTY | FLAGS_CONTENT_SIZE_DIRTY ),
};
Static Node * create () // static Constructor
{
Node *Ret= New (Std::Nothrow) Node (); // initialize a Node
If (Ret&&Ret-> Init () // call init to initialize the Node attribute. In the definition, init is a virtual function and can be reloaded.
{
Ret-> Autorelease (); // Add to the Auto Release pool
}
Else
{
CC_SAFE_DELETE (Ret);
}
ReturnRet;
}
VirtualStd::StringGetDescription () const;
LocalZOrder is the key to sorting its sibling nodes. Its parent node sorts all its subnodes Based on LocalZOrder. if the two nodes have the same LocalZOrder, they are first added to the Child queue before and after.
Of course, this LocalZOrder can be used to implement the 3D conversion algorithm for the scenario diagram. All nodes whose LocalZOrder value is less than zero are in the left subtree, and nodes whose LocalZOrder value is greater than zero are in the right subtree.
Virtual void setLocalZOrder (intLocalZOrder); // Set LocalZOrder
CC_DEPRECATED_ATTRIBUTE virtual void setZOrder (intLocalZOrder) {SetLocalZOrder (LocalZOrder);}
CC_DEPRECATED_ATTRIBUTE virtual void _ setLocalZOrder (intZ);
Virtual int getLocalZOrder () const {return _ localZOrder;} // obtain LocalZOrder
CC_DEPRECATED_ATTRIBUTE virtual int getZOrder () const {return getLocalZOrder ();}
Define the Order of nodes to be rendered: the smaller the global Z Order, the more rendering. If two or more nodes have the same Global Z Order, the rendering Order cannot be guaranteed.
By default, the Global Z Order of all nodes is zero, which means that the scene layer Order is used to render nodes by default. Global Z Order is useful when we need to make the Order of common layers different from the rendering Order.
Restriction: Global Z Order cannot be applied to those nodes with a radical node set as the ancestor.
Virtual void setGlobalZOrder (floatGlobalZOrder); // Set global Z Order
Virtual float getGlobalZOrder () const {return _ globalZOrder;} // obtain global Z Order
Virtual void setScaleX (floatScaleX); // Set the zooming factor in the X direction. Note that the physical rigid body does not support this function.
Virtual float getScaleX () const; // gets the X Scaling Factor
Virtual void setScaleY (floatScaleY);
Virtual float getScaleY () const;
Virtual void setScaleZ (floatScaleZ);
Virtual float getScaleZ () const;
Virtual void setScale (floatScale); // Set XYZ to use the same scaling factor
Virtual float getScale () const; // returns the same result when the scaling factor is the same.
Virtual void setScale (floatScaleX, FloatScaleY); // Sets the XY scaling factor.
Set the coordinates of the node corresponding to its parent node. We use the Vec2 object to set the coordinates. If you need to set the node in the center of the screen, you can use the following code:
Size size = Director: getInstance ()-> getWinSize ();
Node-> setPosition (size. width/2, size. height/2 );
Virtual void setPosition (const Vec2 &Position); // Set the node position. position is an OpenGl coordinate.
Set the position (x, y) to a value between 0 and 1. Pos (with a value between 0 and 1) can be calculated in pixels using the following code:
Void setNormalizedPosition (Vec2 pos ){
Size s = getParent ()-> getContentSize ();
_ Position = pos * s;
}
Virtual void setNormalizedPosition (const Vec2 &Position); // Sets the normalized position.
Virtual const Vec2 & getPosition () const; // obtain the position of a node in its parent node Coordinate
Virtual const Vec2 & getNormalizedPosition () const;
Virtual void setPosition (floatX, FloatY); // Set the Coordinate Position of the node relative to its parent node. Use this function to compare it with the virtual void setPosition (const Vec2 &Position) Is more efficient, because the latter needs to use constructor to construct a Vec2 object.
Virtual void getPosition (float *X, Float *Y) Const; // same as above, return values to x and y, which is more efficient than return values to vec2.
Virtual void setPositionX (floatX); // Set the X coordinate (relative to the parent node coordinate)
Virtual float getPositionX (void) const; // obtain the X coordinate (relative to the parent node coordinate)
Virtual void setPositionY (floatY);
Virtual float getPositionY (void) const;
Virtual void setPosition3D (const Vec3 &Position); // Set the three-dimensional coordinates (relative to the coordinates of the parent node)
Virtual Vec3 getPosition3D () const; // returns the 3D coordinates (relative to the coordinates of the parent node)
Virtual void setPositionZ (floatPositionZ); // Set the OpenGL Z value. OpenGL deep buffering and deep testing are disabled by default. You need to enable them to use this feature correctly.
CC_DEPRECATED_ATTRIBUTE virtual void setVertexZ (floatVertexZ) {SetPositionZ (VertexZ);}
Virtual float getPositionZ () const;
CC_DEPRECATED_ATTRIBUTE virtual float getVertexZ () const {return getPositionZ ();}
Change the X-direction angle (degree ). This function is different from setRotationalSkew () and setSkew (). The first is used to simulate the Flash skew function, and the second is used to simulate the actual skew function. The rigid body of an object is not supported.
Virtual void setSkewX (floatSkewX); // Set the tilt angle skewX corresponding to X. The default value is zero and the unit is degree.
Virtual float getSkewX () const;
Virtual void setSkewY (floatSkewY);
Virtual float getSkewY () const;
The anchor is the basis for all conversions and positional conversions. The anchor is like a parent node that uses a needle to separate the child node. The position of the needle is the anchor of the child node. The anchor is normalized. () indicates the lower left corner, and () indicates the upper right corner. The default anchor is (0.5, 0.5), that is, the node center. If a node is a physical rigid body, its anchor can only be a node center and cannot be modified.
Virtual void setAnchorPoint (const Vec2 &AnchorPoint); // Set the anchor
Virtual const Vec2 & getAnchorPoint () const; // returns a conflict
Virtual const Vec2 & getAnchorPointInPoints () const; // return the anchor point of the corresponding pixel.
ContentSize indicates the actual size of a node. no matter whether the node is scaled or rotated, its size remains unchanged. All nodes have a size. The scenario and layer have a screen size of ContentSize.
Virtual void setContentSize (const Size &ContentSize); // Set ContentSize
Virtual const Size & getContentSize () const; // return ContentSize
Virtual void setVisible (boolVisible); // Sets whether the image is visible.
Virtual bool isVisible () const; // determines whether it is visible
Virtual void setRotation (floatRotation); // Set the rotation angle. The positive value is clockwise and the negative value is clockwise.
Virtual float getRotation () const; // returns the rotation angle.
Virtual void setRotation3D (const Vec3 &Rotation); // Sets the angle for 3D selection, which is not supported by physical rigid bodies.
Virtual Vec3 getRotation3D () const;
Virtual void setRotationQuat (const Quaternion &Quat); // Set the four-element rotation volume
Rotationusing quaternion, if _ rotationZ_X = _ rotationZ_Y, _ rotationQuat = RotationZ_X * RotationY * RotationX, else _ rotationQuat = RotationY * RotationX
Virtual Quaternion getRotationQuat () const; // returns the four-element rotation.
Virtual void setRotationSkewX (floatRotationX);
CC_DEPRECATED_ATTRIBUTE virtual void setRotationX (floatRotationX) {Return setRotationSkewX (RotationX);}
Virtual float getRotationSkewX () const;
CC_DEPRECATED_ATTRIBUTE virtual float getRotationX () const {return getRotationSkewX ();}
Virtual void setRotationSkewY (floatRotationY);
CC_DEPRECATED_ATTRIBUTE virtual void setRotationY (floatRotationY) {Return setRotationSkewY (RotationY);}
Virtual float getRotationSkewY () const;
CC_DEPRECATED_ATTRIBUTE virtual float getRotationY () const {return getRotationSkewY ();}
Void setOrderOfArrival (intOrderOfArrival); // Set the arrival sequence. Use addChild to add nodes in sequence. The smaller the order value, the more drawn the node. If the two children have the same ZOrder, the sequence value can be used to determine who is drawn first.
Int getOrderOfArrival () const; // return the order of arrival of the node, which can be used to determine which node is first added to its parent node.
Virtual void ignoreAnchorPointForPosition (boolIgnore); // When the current node is set to a position, set whether its node is (0, 0 ). Only layers and scenarios can be used. The default value of the function input parameter is false.
Virtual bool isIgnoreAnchorPointForPosition () const;
Virtual void addChild (Node *Child); // If child is added to the node tree, its default ZOrder value is 0. If the child is added to a running node, the onEnter function and the onEnterTransitionDidFinish function will be called.
Virtual void addChild (Node *Child, IntLocalZOrder); Add LocalZOrder
Virtual void addChild (Node *Child, IntLocalZOrder, ConstStd::String&Name);
Virtual Node * getChildByTag (intTag) Const; // use the query tag to return the subnode
Virtual Node * getChildByName (constStd::String&Name) Const; // use the query name to return the subnode
Template
Inline T getChildByName (constStd::String&Name) Const {return static_cast (GetChildByName ( Name));}
Virtual void enumerateChildren (constStd::String&Name,Std::Function Node)> Callback) Const;
Virtual Vector & GetChildren () {return _ children;} // return the child queue of the current node
Virtual const Vector & GetChildren () const {return _ children ;}
Virtual ssize_t getChildrenCount () const; // returns the number of children on the current node.
Virtual void setParent (Node *Parent); Set the parent node of the current node
Virtual Node * getParent () {return _ parent;} // returns the parent Node
Virtual const Node * getParent () const {return _ parent ;}
Virtual void removeFromParent (); // remove the current node from its parent node and clear it
Virtual void removeFromParentAndCleanup (boolCleanup); // Remove and determine whether it is clear. If all the actions and callback functions of this node can be removed, set it to true.
Virtual void removeChild (Node *Child, BoolCleanup= True); // remove a subnode
Virtual void removeChildByTag (intTag, BoolCleanup= True); // use tags to remove sub-nodes
Virtual void removeChildByName (constStd::String&Name, BoolCleanup= True );
Virtual void removeAllChildren (); // remove all child nodes
Virtual void removeAllChildrenWithCleanup (boolCleanup); // Remove all children and clear them
Virtual void reorderChild (Node *Child, IntLocalZOrder); // Re-sort by localZOrder of child.
Virtual void sortAllChildren (); // sort all children before painting
Virtual int getTag () const; // return the node tag
Virtual void setTag (intTag); // Set the tag
VirtualStd::StringGetName () const;
Virtual void setName (constStd::String&Name);
Virtual void * getUserData () {return _ userData;} // returns the User Data Pointer, which can be of any type
Virtual const void * getUserData () const {return _ userData ;}
Virtual void setUserData (void *UserData); // Set user data (pointer), remember to manually check the memory
Virtual Ref * getUserObject () {return _ userObject;} // return the user-assigned object (Ref *)
Virtual const Ref * getUserObject () const {return _ userObject ;}
Virtual void setUserObject (Ref *UserObject); // Similar to user data, but this can be automatically released