Class cc.Node
Constructor Attributes | Constructor Name and Description |
---|---|
cc.Node()
cc.Node is the main element. |
Method Summary
Class Detail
cc.Node is the main element. Anything thats gets drawn or contains things that get drawn is a cc.Node.
The most popular cc.Nodes are: cc.Scene, cc.Layer, cc.Sprite, cc.Menu.
The main features of a cc.Node are:
- They can contain other cc.Node nodes (addChild, getChildByTag, removeChild, etc)
- They can schedule periodic callback (schedule, unschedule, etc)
- They can execute actions (runAction, stopAction, etc)
Some cc.Node nodes provide extra functionality for them or their children.
Subclassing a cc.Node usually means (one/all) of:
- overriding init to initialize resources and schedule callbacks
- create callbacks to handle the advancement of time
- overriding draw to render the node
Features of cc.Node:
- position
- scale (x, y)
- rotation (in degrees, clockwise)
- anchor point
- size
- visible
- z-order
- openGL z position
Default values:
- rotation: 0
- position: (x=0,y=0)
- scale: (x=1,y=1)
- contentSize: (x=0,y=0)
- anchorPoint: (x=0,y=0)
Limitations:
- A cc.Node is a "void" object. It doesn't have a texture
Order in transformations with grid disabled
-# The node will be translated (position)
-# The node will be rotated (rotation)
-# The node will be scaled (scale)
Order in transformations with grid enabled
-# The node will be translated (position)
-# The node will be rotated (rotation)
-# The node will be scaled (scale)
-# The grid will capture the screen
-# The node will be moved according to the camera values (camera)
-# The grid will render the captured screen
// example cc.Sprite = cc.Node.extend({}); cc.Sprite.initWithImage = function(){ };
Field Detail
The matrix is in Pixels.
Method Detail
-
addChild(child, zOrder, tag)
"add" logic MUST only be on this method
If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
- Parameters:
- {cc.Node} child
- A child node
- {Number} zOrder Optional
- Z order for drawing priority. Please refer to setZOrder(int)
- {Number} tag Optional
- A integer to identify the node easily. Please refer to setTag(int)
-
addComponent(component)adds a component
- Parameters:
- {cc.Component} component
-
cleanup()Stops all running actions and schedulers
-
{cc.Point} convertToNodeSpace(worldPoint)Converts a Point to node (local) space coordinates. The result is in Points.
- Parameters:
- {cc.Point} worldPoint
- Returns:
- {cc.Point}
-
{cc.Point} convertToNodeSpaceAR(worldPoint)Converts a Point to node (local) space coordinates. The result is in Points.
treating the returned/received node point as anchor relative.- Parameters:
- {cc.Point} worldPoint
- Returns:
- {cc.Point}
-
{cc.Point} convertTouchToNodeSpace(touch)convenience methods which take a cc.Touch instead of cc.Point
- Parameters:
- {cc.Touch} touch
- Returns:
- {cc.Point}
-
{cc.Point} convertTouchToNodeSpaceAR(touch)converts a cc.Touch (world coordinates) into a local coordiante. This method is AR (Anchor Relative).
- Parameters:
- {cc.Touch} touch
- Returns:
- {cc.Point}
-
{cc.Point} convertToWorldSpace(nodePoint)Converts a Point to world space coordinates. The result is in Points.
- Parameters:
- {cc.Point} nodePoint
- Returns:
- {cc.Point}
-
{cc.Point} convertToWorldSpaceAR(nodePoint)Converts a local Point to world space coordinates.The result is in Points.
treating the returned/received node point as anchor relative.- Parameters:
- {cc.Point} nodePoint
- Returns:
- {cc.Point}
-
allocates and initializes a node.
// example var node = cc.Node.create();
- Returns:
- {cc.Node}
-
{String} description()Gets the description string. It makes debugging easier.
- Returns:
- {String}
-
draw(ctx)
Override this method to draw your own node.
The following GL states will be enabled by default:
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_TEXTURE_2D);AND YOU SHOULD NOT DISABLE THEM AFTER DRAWING YOUR NODE
But if you enable any other GL state, you should disable it after drawing your node.
- Parameters:
- {CanvasContext} ctx
-
{cc.Action} getActionByTag(tag)Gets an action from the running action list by its tag.
- Parameters:
- {Number} tag
- Returns:
- {cc.Action} The action object with the given tag.
- See:
- setTag(int), getTag().
-
{cc.ActionManager} getActionManager()
Gets the CCActionManager object that is used by all actions.
(IMPORTANT: If you set a new cc.ActionManager, then previously created actions are going to be removed.)- Returns:
- {cc.ActionManager} A CCActionManager object.
- See:
- setActionManager()
-
{cc.Point} getAnchorPoint()
anchorPoint is the point around which all transformations and positioning manipulations take place.
It's like a pin in the node where it is "attached" to its parent.
The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
But you can use values higher than (1,1) and lower than (0,0) too.
The default anchorPoint is (0.5,0.5), so it starts in the center of the node.- Returns:
- {cc.Point} The anchor point of node.
-
{cc.Point} getAnchorPointInPoints()The anchorPoint in absolute pixels.
you can only read it. If you wish to modify it, use anchorPoint instead- Returns:
- {cc.Point} The anchor point in absolute pixels.
- See:
- getAnchorPoint()
-
{cc.Rect} getBoundingBox()Returns a "local" axis aligned bounding box of the node.
The returned box is relative only to its parent.- Returns:
- {cc.Rect}
-
{cc.Rect} getBoundingBoxToWorld()returns a "world" axis aligned bounding box of the node.
- Returns:
- {cc.Rect}
-
{cc.Camera} getCamera()Returns a camera object that lets you move the node using a gluLookAt
var camera = node.getCamera(); camera.setEye(0, 0, 415/2); camera.setCenter(0, 0, 0);
- Returns:
- {cc.Camera} A CCCamera object that lets you move the node using a gluLookAt
-
{cc.Node} getChildByTag(aTag)Gets a child from the container given its tag
- Parameters:
- {Number} aTag
- An identifier to find the child node.
- Returns:
- {cc.Node} a CCNode object whose tag equals to the input parameter
-
{Array} getChildren()Return an array of children
Composing a "tree" structure is a very important feature of CCNode//This sample code traverses all children nodes, and set their position to (0,0) var allChildren = parent.getChildren(); for(var i = 0; i< allChildren.length; i++) { allChildren[i].setPosition(0,0); }
- Returns:
- {Array} An array of children
-
{Number} getChildrenCount()Get the amount of children.
- Returns:
- {Number} The amount of children.
-
{cc.Component} getComponent(name)gets a component by its name
- Parameters:
- {String} name
- Returns:
- {cc.Component} gets a component by its name
-
{cc.Size} getContentSize()
The untransformed size of the node.
The contentSize remains the same no matter the node is scaled or rotated.
All nodes has a size. Layer and Scene has the same size of the screen.- Returns:
- {cc.Size} The untransformed size of the node.
-
{Number} getGLServerState()Returns the state of OpenGL server side.
- Returns:
- {Number} The state of OpenGL server side.
-
{cc.GridBase} getGrid()Returns a grid object that is used when applying effects
- Returns:
- {cc.GridBase} A CCGrid object that is used when applying effects
-
{Number} getNumberOfRunningActions()Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).
Composable actions are counted as 1 action. Example:
If you are running 1 Sequence of 7 actions, it will return 1.
If you are running 7 Sequences of 2 actions, it will return 7.- Returns:
- {Number} The number of actions that are running plus the ones that are schedule to run
-
{Number} getOrderOfArrival()Returns the arrival order, indicates which children is added previously.
- Returns:
- {Number} The arrival order.
-
{cc.Node} getParent()Returns a pointer to the parent node
- Returns:
- {cc.Node} A pointer to the parent node
-
{cc.Point} getPosition()
Position (x,y) of the node in OpenGL coordinates. (0,0) is the left-bottom corner.
- Returns:
- {cc.Point} The position (x,y) of the node in OpenGL coordinates
-
{Number} getPositionX()
- Returns:
- {Number}
-
{Number} getPositionY()
- Returns:
- {Number}
-
{Number} getRotation()The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW.
- Returns:
- {Number} The rotation of the node in degrees.
-
{Number} getRotationX()The rotation (angle) of the node in degrees. 0 is the default rotation angle.
Positive values rotate node CW. It only modifies the X rotation performing a horizontal rotational skew . (support only in WebGl rendering mode)- Returns:
- {Number} The X rotation in degrees.
-
{Number} getRotationY()The rotation (angle) of the node in degrees. 0 is the default rotation angle.
Positive values rotate node CW. It only modifies the Y rotation performing a vertical rotational skew .- Returns:
- {Number} The Y rotation in degrees.
-
{Number} getScale()Get the scale factor of the node.
- Returns:
- {Number}
-
{Number} getScaleX()Returns the scale factor on X axis of this node
- Returns:
- {Number} The scale factor on X axis.
-
{Number} getScaleY()Returns the scale factor on Y axis of this node
- Returns:
- {Number} The scale factor on Y axis.
-
{cc.Scheduler} getScheduler()
cc.Scheduler used to schedule all "updates" and timers.
IMPORTANT: If you set a new cc.Scheduler, then previously created timers/update are going to be removed.- Returns:
- {cc.Scheduler} A CCScheduler object.
-
{cc.GLProgram} getShaderProgram()Return the shader program currently used for this node
- Returns:
- {cc.GLProgram} The shader program currelty used for this node
-
{Number} getSkewX()
get the skew degrees in X The X skew angle of the node in degrees.
This angle describes the shear distortion in the X direction.
Thus, it is the angle between the Y axis and the left edge of the shape The default skewX angle is 0. Positive values distort the node in a CW direction.- Returns:
- {Number} The X skew angle of the node in degrees.
-
{Number} getSkewY()
get the skew degrees in Y
The Y skew angle of the node in degrees.
This angle describes the shear distortion in the Y direction.
Thus, it is the angle between the X axis and the bottom edge of the shape
The default skewY angle is 0. Positive values distort the node in a CCW direction.
- Returns:
- {Number} The Y skew angle of the node in degrees.
-
{Number} getTag()Returns a tag that is used to identify the node easily.
//You can set tags to node then identify them easily. // set tags node1.setTag(TAG_PLAYER); node2.setTag(TAG_MONSTER); node3.setTag(TAG_BOSS); parent.addChild(node1); parent.addChild(node2); parent.addChild(node3); // identify by tags var allChildren = parent.getChildren(); for(var i = 0; i < allChildren.length; i++){ switch(node.getTag()) { case TAG_PLAYER: break; case TAG_MONSTER: break; case TAG_BOSS: break; } }
- Returns:
- {Number} An integer that identifies the node.
-
{object} getUserData()
Returns a custom user data pointer
You can set everything in UserData pointer, a data block, a structure or an object.- Returns:
- {object} A custom user data pointer
-
{object} getUserObject()Returns a user assigned CCObject.
Similar to userData, but instead of holding a void* it holds an id- Returns:
- {object} A user assigned CCObject
-
{Number} getVertexZ()Gets WebGL Z vertex of this node.
- Returns:
- {Number} WebGL Z vertex of this node
-
{Number} getZOrder()zOrder getter
- Returns:
- {Number}
-
ignoreAnchorPointForPosition(newValue)
Sets whether the anchor point will be (0,0) when you position this node.
This is an internal method, only used by CCLayer and CCScene. Don't call it outside framework.
The default value is false, while in CCLayer and CCScene are true- Parameters:
- {Boolean} newValue
- true if anchor point will be (0,0) when you position this node
-
{boolean} init()Initializes the instance of cc.Node
- Returns:
- {boolean} Whether the initialization was successful.
-
{Boolean} isIgnoreAnchorPointForPosition()Gets whether the anchor point will be (0,0) when you position this node.
- Returns:
- {Boolean} true if the anchor point will be (0,0) when you position this node.
- See:
- ignoreAnchorPointForPosition(bool)
-
{Boolean} isRunning()
Returns whether or not the node accepts event callbacks.
Running means the node accept event callbacks like onEnter(), onExit(), update()- Returns:
- {Boolean} Whether or not the node is running.
-
{Boolean} isVisible()Determines if the node is visible
- Returns:
- {Boolean} true if the node is visible, false if the node is hidden.
- See:
- setVisible(bool)
-
{cc.AffineTransform} nodeToWorldTransform()Returns the world affine transform matrix. The matrix is in Pixels.
- Returns:
- {cc.AffineTransform}
-
onEnter()
Event callback that is invoked every time when CCNode enters the 'stage'.
If the CCNode enters the 'stage' with a transition, this event is called when the transition starts.
During onEnter you can't access a "sister/brother" node.
If you override onEnter, you shall call its parent's one, e.g., CCNode::onEnter(). -
onEnterTransitionDidFinish()
Event callback that is invoked when the CCNode enters in the 'stage'.
If the CCNode enters the 'stage' with a transition, this event is called when the transition finishes.
If you override onEnterTransitionDidFinish, you shall call its parent's one, e.g. CCNode::onEnterTransitionDidFinish() -
onExit()
callback that is called every time the cc.Node leaves the 'stage'.
If the cc.Node leaves the 'stage' with a transition, this callback is called when the transition finishes.
During onExit you can't access a sibling node.
If you override onExit, you shall call its parent's one, e.g., CCNode::onExit(). -
onExitTransitionDidStart()
callback that is called every time the cc.Node leaves the 'stage'.
If the cc.Node leaves the 'stage' with a transition, this callback is called when the transition starts. -
{cc.AffineTransform} parentToNodeTransform()Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
The matrix is in Pixels.- Returns:
- {cc.AffineTransform}
-
pauseSchedulerAndActions()Pauses all scheduled selectors and actions.
This method is called internally by onExit -
removeAllChildren(cleanup)Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
If the cleanup parameter is not passed, it will force a cleanup.
- Parameters:
- {Boolean | null} cleanup
- true if all running actions on all children nodes should be cleanup, false otherwise.
-
removeAllChildrenWithCleanup(cleanup)Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
- Parameters:
- {Boolean | null} cleanup
-
removeAllComponents()removes all components
-
removeChild(child, cleanup)
Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.
If the cleanup parameter is not passed, it will force a cleanup.
"remove" logic MUST only be on this method
If a class wants to extend the 'removeChild' behavior it only needs
to override this method- Parameters:
- {cc.Node} child
- The child node which will be removed.
- {Boolean|null} cleanup Optional, Default: null
- true if all running actions and callbacks on the child node will be cleanup, false otherwise.
-
removeChildByTag(tag, cleanup)Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter. If the cleanup parameter is not passed, it will force a cleanup.
- Parameters:
- {Number} tag
- An integer number that identifies a child node
- {Boolean} cleanup
- true if all running actions and callbacks on the child node will be cleanup, false otherwise.
- See:
- removeChildByTag(int, bool)
-
removeComponent(name)removes a component by its name
- Parameters:
- {String} name
-
removeFromParent(cleanup)Remove itself from its parent node. If cleanup is true, then also remove all actions and callbacks.
If the cleanup parameter is not passed, it will force a cleanup.
If the node orphan, then nothing happens.- Parameters:
- {Boolean} cleanup
- true if all actions and callbacks on this node should be removed, false otherwise.
- See:
- removeFromParentAndCleanup(bool)
-
removeFromParentAndCleanup(cleanup)Removes this node itself from its parent node.
If the node orphan, then nothing happens.- Parameters:
- {Boolean} cleanup
- true if all actions and callbacks on this node should be removed, false otherwise.
-
reorderChild(child, zOrder)Reorders a child according to a new z value.
The child MUST be already added.- Parameters:
- {cc.Node} child
- An already added child node. It MUST be already added.
- {Number} zOrder
- Z order for drawing priority. Please refer to setZOrder(int)
-
resumeSchedulerAndActions()Resumes all scheduled selectors and actions.
This method is called internally by onEnter -
retain()Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB, and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB. This is a hack, and should be removed once JSB fixes the retain/release bug
-
{cc.Action} runAction(action)Executes an action, and returns the action that is executed.
The node becomes the action's target. Refer to CCAction::getTarget()- Parameters:
- {cc.Action} action
- Returns:
- {cc.Action} An Action pointer
-
schedule(callback_fn, interval, repeat, delay)Schedules a custom selector.
If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.- Parameters:
- {function} callback_fn
- A function wrapped as a selector
- {Number} interval
- Tick interval in seconds. 0 means tick every frame. If interval = 0, it's recommended to use scheduleUpdate() instead.
- {Number} repeat
- The selector will be executed (repeat + 1) times, you can use kCCRepeatForever for tick infinitely.
- {Number} delay
- The amount of time that the first tick will wait before execution.
-
scheduleOnce(callback_fn, delay)Schedules a callback function that runs only once, with a delay of 0 or larger
- Parameters:
- {function} callback_fn
- A function wrapped as a selector
- {Number} delay
- The amount of time that the first tick will wait before execution.
- See:
- schedule(SEL_SCHEDULE, float, unsigned int, float)
-
scheduleUpdate()schedules the "update" method.
It will use the order number 0. This method will be called every frame.
Scheduled methods with a lower order value will be called before the ones that have a higher order value.
Only one "update" method could be scheduled per node. -
scheduleUpdateWithPriority(priority)
schedules the "update" callback function with a custom priority. This callback function will be called every frame.
Scheduled callback functions with a lower priority will be called before the ones that have a higher value.
Only one "update" callback function could be scheduled per node (You can't have 2 'update' callback functions).
- Parameters:
- {Number} priority
-
setActionManager(actionManager)
Sets the cc.ActionManager object that is used by all actions.
- Parameters:
- {cc.ActionManager} actionManager
- A CCActionManager object that is used by all actions.
-
setAdditionalTransform(additionalTransform)
Sets the additional transform.
The additional transform will be concatenated at the end of nodeToParentTransform.
It could be used to simulate `parent-child` relationship between two nodes (e.g. one is in BatchNode, another isn't).
// create a batchNode var batch= cc.SpriteBatchNode.create("Icon-114.png"); this.addChild(batch); // create two sprites, spriteA will be added to batchNode, they are using different textures. var spriteA = cc.Sprite.createWithTexture(batch->getTexture()); var spriteB = cc.Sprite.create("Icon-72.png"); batch.addChild(spriteA); // We can't make spriteB as spriteA's child since they use different textures. So just add it to layer. // But we want to simulate `parent-child` relationship for these two node. this.addChild(spriteB); //position spriteA.setPosition(ccp(200, 200)); // Gets the spriteA's transform. var t = spriteA.nodeToParentTransform(); // Sets the additional transform to spriteB, spriteB's position will based on its pseudo parent i.e. spriteA. spriteB.setAdditionalTransform(t); //scale spriteA.setScale(2); // Gets the spriteA's transform. t = spriteA.nodeToParentTransform(); // Sets the additional transform to spriteB, spriteB's scale will based on its pseudo parent i.e. spriteA. spriteB.setAdditionalTransform(t); //rotation spriteA.setRotation(20); // Gets the spriteA's transform. t = spriteA.nodeToParentTransform(); // Sets the additional transform to spriteB, spriteB's rotation will based on its pseudo parent i.e. spriteA. spriteB.setAdditionalTransform(t);
- Parameters:
- additionalTransform
-
setAnchorPoint(point, y)
Sets the anchor point in percent.
anchorPoint is the point around which all transformations and positioning manipulations take place.
It's like a pin in the node where it is "attached" to its parent.
The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
But you can use values higher than (1,1) and lower than (0,0) too.
The default anchorPoint is (0.5,0.5), so it starts in the center of the node.- Parameters:
- {cc.Point|Number} point
- The anchor point of node or The anchor point.x of node.
- {Number} y Optional
- The anchor point.y of node.
-
setContentSize(size, height)
Sets the untransformed size of the node.
The contentSize remains the same no matter the node is scaled or rotated.
All nodes has a size. Layer and Scene has the same size of the screen.- Parameters:
- {cc.Size|Number} size
- The untransformed size of the node or The untransformed size's width of the node.
- {Number} height Optional
- The untransformed size's height of the node.
-
setGLServerState(state)Sets the state of OpenGL server side.
- Parameters:
- {Number} state
- The state of OpenGL server side.
-
setGrid(grid)Changes a grid object that is used when applying effects
- Parameters:
- {cc.GridBase} grid
- A CCGrid object that is used when applying effects
-
setOrderOfArrival(Var)
Sets the arrival order when this node has a same ZOrder with other children.
A node which called addChild subsequently will take a larger arrival order,
If two children have the same Z order, the child with larger arrival order will be drawn later.- Parameters:
- {Number} Var
- The arrival order.
-
setParent(Var)Sets the parent node
- Parameters:
- {cc.Node} Var
- A pointer to the parent node
-
setPosition(newPosOrxValue, yValue)
Changes the position (x,y) of the node in OpenGL coordinates Usually we use ccp(x,y) to compose CCPoint object. The original point (0,0) is at the left-bottom corner of screen. and Passing two numbers (x,y) is much efficient than passing CCPoint object.
var size = cc.Director.getInstance().getWinSize(); node.setPosition(size.width/2, size.height/2);
- Parameters:
- {cc.Point|Number} newPosOrxValue
- The position (x,y) of the node in coordinates or X coordinate for position
- {Number} yValue Optional
- Y coordinate for position
-
setPositionX(x)
- Parameters:
- {Number} x
-
setPositionY(y)
- Parameters:
- {Number} y
-
setRotation(newRotation)
Sets the rotation (angle) of the node in degrees.
0 is the default rotation angle.
Positive values rotate node clockwise, and negative values for anti-clockwise.- Parameters:
- {Number} newRotation
- The rotation of the node in degrees.
-
setRotationX(rotationX)
Sets the X rotation (angle) of the node in degrees which performs a horizontal rotational skew.
0 is the default rotation angle.
Positive values rotate node clockwise, and negative values for anti-clockwise.- Parameters:
- {Number} rotationX
- The X rotation in degrees which performs a horizontal rotational skew.
-
setRotationY(rotationY)
Sets the Y rotation (angle) of the node in degrees which performs a vertical rotational skew.
0 is the default rotation angle.
Positive values rotate node clockwise, and negative values for anti-clockwise.- Parameters:
- rotationY
- The Y rotation in degrees.
-
setScale(scale, scaleY)The scale factor of the node. 1.0 is the default scale factor. It modifies the X and Y scale at the same time.
- Parameters:
- {Number} scale
- or scaleX value
- {Number} scaleY Optional
-
setScaleX(newScaleX)
Changes the scale factor on X axis of this node
The deafult value is 1.0 if you haven't changed it before- Parameters:
- {Number} newScaleX
- The scale factor on X axis.
-
setScaleY(newScaleY)
Changes the scale factor on Y axis of this node
The Default value is 1.0 if you haven't changed it before.- Parameters:
- {Number} newScaleY
- The scale factor on Y axis.
-
setScheduler(scheduler)
Sets a CCScheduler object that is used to schedule all "updates" and timers.
- Parameters:
- scheduler
- A cc.Scheduler object that is used to schedule all "update" and timers.
-
setShaderProgram(newShaderProgram)
Sets the shader program for this node Since v2.0, each rendering node must set its shader program. It should be set in initialize phase.
node.setShaderProgram(cc.ShaderCache.getInstance().programForKey(cc.SHADER_POSITION_TEXTURECOLOR));
- Parameters:
- {cc.GLProgram} newShaderProgram
- The shader program which fetchs from CCShaderCache.
-
setSkewX(newSkewX)
Changes the X skew angle of the node in degrees.
This angle describes the shear distortion in the X direction.
Thus, it is the angle between the Y axis and the left edge of the shape
The default skewX angle is 0. Positive values distort the node in a CW direction.- Parameters:
- {Number} newSkewX
- The X skew angle of the node in degrees.
-
setSkewY(newSkewY)
Changes the Y skew angle of the node in degrees. This angle describes the shear distortion in the Y direction. Thus, it is the angle between the X axis and the bottom edge of the shape The default skewY angle is 0. Positive values distort the node in a CCW direction.
- Parameters:
- {Number} newSkewY
- The Y skew angle of the node in degrees.
-
setTag(Var)Changes the tag that is used to identify the node easily.
Please refer to getTag for the sample code.- Parameters:
- {Number} Var
- A integer that identifies the node.
-
setUserData(Var)
Sets a custom user data pointer
You can set everything in UserData pointer, a data block, a structure or an object, etc.- Parameters:
- {object} Var
- A custom user data
-
setUserObject(newValue)
Returns a user assigned CCObject
Similar to UserData, but instead of holding a void* it holds an object.
The UserObject will be retained once in this method, and the previous UserObject (if existed) will be release.
The UserObject will be released in CCNode's destruction.- Parameters:
- {object} newValue
- A user assigned CCObject
-
setVertexZ(Var)
Sets the real WebGL Z vertex.
Differences between openGL Z vertex and cocos2d Z order:
- OpenGL Z modifies the Z vertex, and not the Z order in the relation between parent-children
- OpenGL Z might require to set 2D projection
- cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: vertexZ = 0
- Parameters:
- {Number} Var
-
setVisible(Var)Sets whether the node is visible
The default value is true, a node is default to visible- Parameters:
- {Boolean} Var
- true if the node is visible, false if the node is hidden.
-
setZOrder(z)
Sets the Z order which stands for the drawing order, and reorder this node in its parent's children array.
The Z order of node is relative to its "brothers": children of the same parent.
It's nothing to do with OpenGL's z vertex. This one only affects the draw order of nodes in cocos2d.
The larger number it is, the later this node will be drawn in each message loop.
Please refer to setVertexZ(float) for the difference.- Parameters:
- {Number} z
- Z order of this node.
-
sortAllChildren()
Sorts the children array once before drawing, instead of every time when a child is added or reordered.
This approach can improves the performance massively. -
stopAction(action)Stops and removes an action from the running action list.
- Parameters:
- {cc.Action} action
- An action object to be removed.
-
stopActionByTag(tag)Removes an action from the running action list by its tag.
- Parameters:
- {Number} tag
- A tag that indicates the action to be removed.
-
stopAllActions()Stops and removes all actions from the running action list .
-
transformAncestors()performs OpenGL view-matrix transformation of it's ancestors.
Generally the ancestors are already transformed, but in certain cases (eg: attaching a FBO)
it's necessary to transform the ancestors again. -
unschedule(callback_fn)unschedules a custom callback function.
- Parameters:
- {function} callback_fn
- A function wrapped as a selector
- See:
- schedule(SEL_SCHEDULE, float, unsigned int, float)
-
unscheduleAllCallbacks()unschedule all scheduled callback functions: custom callback functions, and the 'update' callback function.
Actions are not affected by this method. -
unscheduleUpdate()unschedules the "update" method.
- See:
- scheduleUpdate();
-
update(dt)Update will be called automatically every frame if "scheduleUpdate" is called, and the node is "live"
(override me)- Parameters:
- {Number} dt
- deltaTime
-
updateTransform()
Calls children's updateTransform() method recursively.
This method is moved from CCSprite, so it's no longer specific to CCSprite.
As the result, you apply CCSpriteBatchNode's optimization on your customed CCNode.
e.g., batchNode->addChild(myCustomNode), while you can only addChild(sprite) before. -
{cc.AffineTransform} worldToNodeTransform()Returns the inverse world affine transform matrix. The matrix is in Pixels.
- Returns:
- {cc.AffineTransform}