coco2d-x 2.0学习系列(2):CCNode

coco2d-x 2.0学习系列(二):CCNode
CCNode是一个核心的类,直接继承至CCObject,CCObject类是cocos2d-x中所有对象的基类,它封装了对象的引用计数和自动释放功能。CCNode是场景、层、菜单、精灵等所有节点的父类。


CCNode是cocos2d-x的渲染链,cocos2d-x同时只能渲染一个scene,因此scene是渲染的根节点,一般树的渲染顺序是scene添加n个CCLayer,一个CCLayer添加n个CCSprite或者CCMenu,CCSprite还可以添加CCParticleSystem,这样就构建了一个渲染树,cocos2d-x历遍这个树来将图像显示在屏幕上。
coco2d-x->visit() 调用Child的zOrder<0的visit()函数,然后调用draw()函数。再调用Child的zOrder>=0的visit()函数。(深度优先的算法 zOrder大的显示在最上层)。
主要函数:
Public Member Functions
virtual CCCamera * 	getCamera ()
 获取节点相机 
virtual bool 	isRunning ()
virtual void 	cleanup (void)
 	停止节点所有运行的 actions 和schedulers. 
 
virtual void 	draw (void)
绘制自己
virtual void 	visit (void)
访问节点 
CCRect 	boundingBox (void)
 	Returns a "local" axis aligned bounding box of the node. 
 
Setters & Getters for Graphic Peroperties
virtual void 	setZOrder (int zOrder)
设置节点顺序,值越大显示越靠前
virtual void 	_setZOrder (int z)
 	Sets the z order which stands for the drawing order. 
 
virtual int 	getZOrder ()
 	获取节点顺序
 
virtual void 	setVertexZ (float vertexZ)
 	Sets the real OpenGL Z vertex. 
 
virtual float 	getVertexZ ()
 	Gets OpenGL Z vertex of this node. 
 
virtual void 	setScaleX (float fScaleX)
 	Changes the scale factor on X axis of this node. 
 
virtual float 	getScaleX ()
 	Returns the scale factor on X axis of this node. 
 
virtual void 	setScaleY (float fScaleY)
 	Changes the scale factor on Y axis of this node. 
 
virtual float 	getScaleY ()
 	Returns the scale factor on Y axis of this node. 
 
virtual void 	setScale (float scale)
 	Changes both X and Y scale factor of the node. 
 
virtual float 	getScale ()
 	Gets the scale factor of the node, when X and Y have the same scale factor. 
 
virtual void 	setPosition (const CCPoint &position)
 设置节点位置 
virtual const CCPoint & 	getPosition ()
 	获取节点位置
 
void 	setPosition (float x, float y)
 	Sets position in a more efficient way. 
 
void 	getPosition (float *x, float *y)
 	Gets position in a more efficient way, returns two number instead of a CCPoint object. 
 
void 	setPositionX (float x)
 	Gets/Sets x or y coordinate individually for position. 
 
float 	getPositionX (void)
 
void 	setPositionY (float y)
 
float 	getPositionY (void)
 
virtual void 	setSkewX (float fSkewX)
 	Changes the X skew angle of the node in degrees. 
 
virtual float 	getSkewX ()
 	Returns the X skew angle of the node in degrees. 
 
virtual void 	setSkewY (float fSkewY)
 	Changes the Y skew angle of the node in degrees. 
 
virtual float 	getSkewY ()
 	Returns the Y skew angle of the node in degrees. 
 
virtual void 	setAnchorPoint (const CCPoint &anchorPoint)
 	Sets the anchor point in percent. 
 
virtual const CCPoint & 	getAnchorPoint ()
 	//获取节点的锚点的位置
 
virtual const CCPoint & 	getAnchorPointInPoints ()
 	Returns the anchorPoint in absolute pixels. 
 
virtual void 	setContentSize (const CCSize &contentSize)
 	Sets the untransformed size of the node. 
 
virtual const CCSize & 	getContentSize ()
 	Returns the untransformed size of the node. 
 
virtual void 	setVisible (bool visible)
 	Sets whether the node is visible. 
 
virtual bool 	isVisible ()
 	Determines if the node is visible. 
 
virtual void 	setRotation (float fRotation)
 	Sets the rotation (angle) of the node in degrees. 
 
virtual float 	getRotation ()
 	Returns the rotation of the node in degrees. 
 
virtual void 	setRotationX (float fRotaionX)
 	Sets the X rotation (angle) of the node in degrees which performs a horizontal rotational skew. 
 
virtual float 	getRotationX ()
 	Gets the X rotation (angle) of the node in degrees which performs a horizontal rotation skew. 
 
virtual void 	setRotationY (float fRotationY)
 	Sets the Y rotation (angle) of the node in degrees which performs a vertical rotational skew. 
 
virtual float 	getRotationY ()
 	Gets the Y rotation (angle) of the node in degrees which performs a vertical rotational skew. 
 
virtual void 	setOrderOfArrival (unsigned int uOrderOfArrival)
 	Sets the arrival order when this node has a same ZOrder with other children. 
 
virtual unsigned int 	getOrderOfArrival ()
 	Returns the arrival order, indecates which children is added previously. 
 
virtual void 	setGLServerState (ccGLServerState glServerState)
 	Sets the state of OpenGL server side. 
 
virtual ccGLServerState 	getGLServerState ()
 	Returns the state of OpenGL server side. 
 
virtual void 	ignoreAnchorPointForPosition (bool ignore)
 	Sets whether the anchor point will be (0,0) when you position this node. 
 
virtual bool 	isIgnoreAnchorPointForPosition ()
 	Gets whether the anchor point will be (0,0) when you position this node. 
 
Children and Parent
virtual void 	addChild (CCNode *child)
 	Adds a child to the container with z-order as 0. 
 
virtual void 	addChild (CCNode *child, int zOrder)
 	Adds a child to the container with a z-order. 
 
virtual void 	addChild (CCNode *child, int zOrder, int tag)
 	Adds a child to the container with z order and tag. 
 
CCNode * 	getChildByTag (int tag)
 	Gets a child from the container with its tag. 
 
virtual CCArray * 	getChildren ()
 	Return an array of children. 
 
unsigned int 	getChildrenCount (void)
 	Get the amount of children. 
 
virtual void 	setParent (CCNode *parent)
 	Sets the parent node. 
 
virtual CCNode * 	getParent ()
 	Returns a pointer to the parent node. 
 
virtual void 	removeFromParent ()
 	Removes this node itself from its parent node with a cleanup. 
 
virtual void 	removeFromParentAndCleanup (bool cleanup)
 	Removes this node itself from its parent node. 
 
virtual void 	removeChild (CCNode *child)
 	Removes a child from the container with a cleanup. 
 
virtual void 	removeChild (CCNode *child, bool cleanup)
 	Removes a child from the container. 
 
virtual void 	removeChildByTag (int tag)
 	Removes a child from the container by tag value with a cleanup. 
 
virtual void 	removeChildByTag (int tag, bool cleanup)
 	Removes a child from the container by tag value. 
 
virtual void 	removeAllChildren ()
 	Removes all children from the container with a cleanup. 
 
virtual void 	removeAllChildrenWithCleanup (bool cleanup)
 	Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter. 
 
virtual void 	reorderChild (CCNode *child, int zOrder)
 	Reorders a child according to a new z value. 
 
virtual void 	sortAllChildren ()
 	Sorts the children array once before drawing, instead of every time when a child is added or reordered. 
 
Grid object for effects
virtual CCGridBase * 	getGrid ()
 	Returns a grid object that is used when applying effects. 
 
virtual void 	setGrid (CCGridBase *pGrid)
 	Changes a grid object that is used when applying effects. 
 
Tag & User data
virtual int 	getTag ()
 	Returns a tag that is used to identify the node easily. 
 
virtual void 	setTag (int nTag)
 	Changes the tag that is used to identify the node easily. 
 
virtual void * 	getUserData ()
 	Returns a custom user data pointer. 
 
virtual void 	setUserData (void *pUserData)
 	Sets a custom user data pointer. 
 
virtual CCObject * 	getUserObject ()
 	Returns a user assigned CCObject. 
 
virtual void 	setUserObject (CCObject *pUserObject)
 	Returns a user assigned CCObject. 
 
Shader Program
virtual CCGLProgram * 	getShaderProgram ()
 	Return the shader program currently used for this node. 
 
virtual void 	setShaderProgram (CCGLProgram *pShaderProgram)
 	Sets the shader program for this node. 
 
Script Bindings for lua
virtual void 	registerScriptHandler (int handler)
 	Registers a script function that will be called in onEnter() & onExit() seires functions. 
 
virtual void 	unregisterScriptHandler (void)
 	Unregisters a script function that will be called in onEnter() & onExit() series functions. 
 
int 	getScriptHandler ()
 	Gets script handler for onEnter/onExit event. 
 
void 	scheduleUpdateWithPriorityLua (int nHandler, int priority)
 	Schedules for lua script.