Node Class

Extends _BaseNode

Module: cc

Class of all entities in Cocos Creator scenes.
Node also inherits from Event Target, it permits Node to dispatch events. For events supported by Node, please refer to Node.EventType

Index

Properties
  • groupIndex Integer Group index of node....
  • group String Group of node....
  • position Vec2 The position (x, y) of the node in its parent's coordinates.
  • x Number x axis position of node.
  • y Number y axis position of node.
  • rotation Number Rotation of node.
  • rotationX Number Rotation on x axis.
  • rotationY Number Rotation on y axis.
  • scaleX Number Scale on x axis.
  • scaleY Number Scale on y axis.
  • skewX Number Skew x
  • skewY Number Skew y
  • opacity Number Opacity of node, default value is 255.
  • cascadeOpacity Boolean Indicate whether node's opacity value affect its child nodes, default value is true.
  • color Color Color of node, default value is white: (255, 255, 255).
  • anchorX Number Anchor point's position on x axis.
  • anchorY Number Anchor point's position on y axis.
  • width Number Width of node.
  • height Number Height of node.
  • zIndex Number Z order in depth which stands for the drawing order.
  • _sgNode _ccsg.Node Current scene graph node for this node.
  • _sizeProvider _ccsg.Node Current active size provider for this node.
  • scale Number The local scale relative to the parent.
  • _components Component[]
  • _prefab PrefabInfo The PrefabInfo object
  • _persistNode Boolean If true, the node is an persist node which won't be destroyed during scene transition.
  • name String Name of node.
  • uuid String The uuid for editor, will be stripped before building project.
  • children Node[] All children nodes.
  • childrenCount Number All children nodes.
  • active Boolean The local active state of this node....
  • activeInHierarchy Boolean Indicates whether this node is active in the scene.
  • tag Number Tag of node.
  • __eventTargets EventTarget[] Register all related EventTargets,...
  • parent Node The parent of the node.
  • _name String
  • _objFlags Number
  • isValid Boolean Indicates whether the object is not yet destroyed.
Methods
Events

Details

Properties

groupIndex

Group index of node.
Which Group this node belongs to will resolve that this node's collision components can collide with which other collision componentns.

meta description
Type Integer
Defined in cocos2d/core/CCNode.js:400
group

Group of node.
Which Group this node belongs to will resolve that this node's collision components can collide with which other collision componentns.

meta description
Type String
Defined in cocos2d/core/CCNode.js:416
position

The position (x, y) of the node in its parent's coordinates.

meta description
Type Vec2
Defined in cocos2d/core/CCNode.js:439
Examples
cc.log("Node Position: " + node.position);
x

x axis position of node.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:447
Examples
node.x = 100;
cc.log("Node Position X: " + node.x);
y

y axis position of node.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:490
Examples
node.y = 100;
cc.log("Node Position Y: " + node.y);
rotation

Rotation of node.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:533
Examples
node.rotation = 90;
cc.log("Node Rotation: " + node.rotation);
rotationX

Rotation on x axis.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:561
Examples
node.rotationX = 45;
cc.log("Node Rotation X: " + node.rotationX);
rotationY

Rotation on y axis.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:587
Examples
node.rotationY = 45;
cc.log("Node Rotation Y: " + node.rotationY);
scaleX

Scale on x axis.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:613
Examples
node.scaleX = 0.5;
cc.log("Node Scale X: " + node.scaleX);
scaleY

Scale on y axis.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:639
Examples
node.scaleY = 0.5;
cc.log("Node Scale Y: " + node.scaleY);
skewX

Skew x

meta description
Type Number
Defined in cocos2d/core/CCNode.js:665
Examples
node.skewX = 0;
cc.log("Node SkewX: " + node.skewX);
skewY

Skew y

meta description
Type Number
Defined in cocos2d/core/CCNode.js:684
Examples
node.skewY = 0;
cc.log("Node SkewY: " + node.skewY);
opacity

Opacity of node, default value is 255.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:703
Examples
node.opacity = 255;
cascadeOpacity

Indicate whether node's opacity value affect its child nodes, default value is true.

meta description
Type Boolean
Defined in cocos2d/core/CCNode.js:730
Examples
cc.log("CascadeOpacity: " + node.cascadeOpacity);
color

Color of node, default value is white: (255, 255, 255).

meta description
Type Color
Defined in cocos2d/core/CCNode.js:756
Examples
node.color = new cc.Color(255, 255, 255);
anchorX

Anchor point's position on x axis.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:781
Examples
node.anchorX = 0;
anchorY

Anchor point's position on y axis.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:806
Examples
node.anchorY = 0;
width

Width of node.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:831
Examples
node.width = 100;
height

Height of node.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:870
Examples
node.height = 100;
zIndex

Z order in depth which stands for the drawing order.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:909
Examples
node.zIndex = 1;
cc.log("Node zIndex: " + node.zIndex);
_sgNode

Current scene graph node for this node.

meta description
Type _ccsg.Node
Defined in cocos2d/core/CCNode.js:943
_sizeProvider

Current active size provider for this node. Size provider can equals to this._sgNode.

meta description
Type _ccsg.Node
Defined in cocos2d/core/CCNode.js:965
scale

The local scale relative to the parent.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:2631
Examples
node.scale = 1;
_components
meta description
Type Component[]
Defined in cocos2d/core/utils/base-node.js:156
_prefab

The PrefabInfo object

meta description
Type PrefabInfo
Defined in cocos2d/core/utils/base-node.js:165
_persistNode

If true, the node is an persist node which won't be destroyed during scene transition. If false, the node will be destroyed automatically when loading a new scene. Default is false.

meta description
Type Boolean
Defined in cocos2d/core/utils/base-node.js:173
name

Name of node.

meta description
Type String
Defined in cocos2d/core/utils/base-node.js:197
Examples
node.name = "New Node";
cc.log("Node Name: " + node.name);
uuid

The uuid for editor, will be stripped before building project.

meta description
Type String
Defined in cocos2d/core/utils/base-node.js:224
Examples
cc.log("Node Uuid: " + node.uuid);
children

All children nodes.

meta description
Type Node[]
Defined in cocos2d/core/utils/base-node.js:243
Examples
var children = node.children;
for (var i = 0; i < children.length; ++i) {
    cc.log("Node: " + children[i]);
}
childrenCount

All children nodes.

meta description
Type Number
Defined in cocos2d/core/utils/base-node.js:261
Examples
var count = node.childrenCount;
cc.log("Node Children Count: " + count);
active

The local active state of this node.
Note that a Node may be inactive because a parent is not active, even if this returns true.
Use Node/activeInHierarchy:property if you want to check if the Node is actually treated as active in the scene.

meta description
Type Boolean
Defined in cocos2d/core/utils/base-node.js:277
Examples
node.active = false;
activeInHierarchy

Indicates whether this node is active in the scene.

meta description
Type Boolean
Defined in cocos2d/core/utils/base-node.js:311
Examples
cc.log("activeInHierarchy: " + node.activeInHierarchy);
tag

Tag of node.

meta description
Type Number
Defined in cocos2d/core/utils/base-node.js:325
Examples
node.tag = 1001;
__eventTargets

Register all related EventTargets, all event callbacks will be removed in _onPreDestroy

meta description
Type EventTarget[]
Defined in cocos2d/core/utils/base-node.js:347
parent

The parent of the node.

meta description
Type Node
Defined in cocos2d/core/utils/base-node.js:365
Examples
node.parent = newNode;
_name
meta description
Type String
Defined in cocos2d/core/platform/CCObject.js:76
_objFlags
meta description
Type Number
Defined in cocos2d/core/platform/CCObject.js:83
isValid

Indicates whether the object is not yet destroyed. (It will not be available after being destroyed)
When an object's destroy is called, it is actually destroyed after the end of this frame. So isValid will return false from the next frame, while isValid in the current frame will still be true. If you want to determine whether the current frame has called destroy, use cc.isValid(obj, true), but this is often caused by a particular logical requirements, which is not normally required.

meta description
Type Boolean
Defined in cocos2d/core/platform/CCObject.js:261
Examples
var node = new cc.Node();
cc.log(node.isValid);    // true
node.destroy();
cc.log(node.isValid);    // true, still valid in this frame
// after a frame...
cc.log(node.isValid);    // false, destroyed in the end of last frame

Methods

constructor
meta description
Defined in cocos2d/core/CCNode.js:937
Parameters
on

Register a callback of a specific event type on Node.
Use this method to register touch or mouse event permit propagation based on scene graph, you can propagate the event to the parents or swallow it by calling stopPropagation on the event.
It's the recommended way to register touch/mouse event for Node, please do not use cc.eventManager directly for Node.

meta description
Returns Function
Defined in cocos2d/core/CCNode.js:1182
Parameters
  • type String A string representing the event type to listen for.
                     See <a href="../classes/Node.html#event_position-changed" class="crosslink">Node Events</a> for all builtin events.
    
  • callback Function The callback that will be invoked when the event is dispatched.
                           The callback is ignored if it is a duplicate (the callbacks are unique).
    
  • target Object The target (this object) to invoke the callback, can be null
  • useCapture Boolean When set to true, the capture argument prevents callback
                           from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE.
                           When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE.
                           Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.
    
Examples
this.node.on(cc.Node.EventType.TOUCH_START, this.memberFunction, this);  // if "this" is component and the "memberFunction" declared in CCClass.
node.on(cc.Node.EventType.TOUCH_START, callback, this.node);
node.on(cc.Node.EventType.TOUCH_MOVE, callback, this.node);
node.on(cc.Node.EventType.TOUCH_END, callback, this.node);
node.on(cc.Node.EventType.TOUCH_CANCEL, callback, this.node);
node.on("anchor-changed", callback, this);
off

Removes the callback previously registered with the same type, callback, target and or useCapture. This method is merely an alias to removeEventListener.

meta description
Defined in cocos2d/core/CCNode.js:1261
Parameters
  • type String A string representing the event type being removed.
  • callback Function The callback to remove.
  • target Object The target (this object) to invoke the callback, if it's not given, only callback without target will be removed
  • useCapture Boolean Specifies whether the callback being removed was registered as a capturing callback or not.
                           If not specified, useCapture defaults to false. If a callback was registered twice,
                           one with capture and one without, each must be removed separately. Removal of a capturing callback
                           does not affect a non-capturing version of the same listener, and vice versa.
    
Examples
this.node.off(cc.Node.EventType.TOUCH_START, this.memberFunction, this);
node.off(cc.Node.EventType.TOUCH_START, callback, this.node);
node.off("anchor-changed", callback, this);
targetOff

Removes all callbacks previously registered with the same target.

meta description
Defined in cocos2d/core/CCNode.js:1290
Parameters
  • target Object The target to be searched for all related callbacks
Examples
node.targetOff(target);
pauseSystemEvents

Pause node related system events registered with the current Node. Node system events includes touch and mouse events. If recursive is set to true, then this API will pause the node system events for the node and all nodes in its sub node tree. Reference: http://cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/internal-events/

meta description
Defined in cocos2d/core/CCNode.js:1305
Parameters
  • recursive Boolean Whether to pause node system events on the sub node tree.
Examples
node.pauseSystemEvents(true);
resumeSystemEvents

Resume node related system events registered with the current Node. Node system events includes touch and mouse events. If recursive is set to true, then this API will resume the node system events for the node and all nodes in its sub node tree. Reference: http://cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/internal-events/

meta description
Defined in cocos2d/core/CCNode.js:1321
Parameters
  • recursive Boolean Whether to resume node system events on the sub node tree.
Examples
node.resumeSystemEvents(true);
runAction

Executes an action, and returns the action that is executed.
The node becomes the action's target. Refer to cc.Action's getTarget()
Calling runAction while the node is not active won't have any effect.
Note:You shouldn't modify the action after runAction, that won't take any effect.
if you want to modify, when you define action plus.

meta description
Returns Action
Defined in cocos2d/core/CCNode.js:1459
Parameters
Examples
var action = cc.scaleTo(0.2, 1, 0.6);
node.runAction(action);
node.runAction(action).repeatForever(); // fail
node.runAction(action.repeatForever()); // right
pauseAllActions

Pause all actions running on the current node. Equals to cc.director.getActionManager().pauseTarget(node).

meta description
Defined in cocos2d/core/CCNode.js:1491
Examples
node.pauseAllActions();
resumeAllActions

Resume all paused actions on the current node. Equals to cc.director.getActionManager().resumeTarget(node).

meta description
Defined in cocos2d/core/CCNode.js:1502
Examples
node.resumeAllActions();
stopAllActions

Stops and removes all actions from the running action list .

meta description
Defined in cocos2d/core/CCNode.js:1513
Examples
node.stopAllActions();
stopAction

Stops and removes an action from the running action list.

meta description
Defined in cocos2d/core/CCNode.js:1524
Parameters
  • action Action An action object to be removed.
Examples
var action = cc.scaleTo(0.2, 1, 0.6);
node.stopAction(action);
stopActionByTag

Removes an action from the running action list by its tag.

meta description
Defined in cocos2d/core/CCNode.js:1537
Parameters
  • tag Number A tag that indicates the action to be removed.
Examples
node.stopAction(1);
getActionByTag

Returns an action from the running action list by its tag.

meta description
Returns Action
Defined in cocos2d/core/CCNode.js:1553
Parameters
Examples
var action = node.getActionByTag(1);
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.</p>

meta description
Returns Number
Defined in cocos2d/core/CCNode.js:1573
Examples
var count = node.getNumberOfRunningActions();
cc.log("Running Action Count: " + count);
getPosition

Returns a copy of the position (x, y) of the node in its parent's coordinates.

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:1602
Examples
cc.log("Node Position: " + node.getPosition());
setPosition

Sets the position (x, y) of the node in its parent's coordinates.
Usually we use cc.v2(x, y) to compose cc.Vec2 object.
and Passing two numbers (x, y) is more efficient than passing cc.Vec2 object.

meta description
Defined in cocos2d/core/CCNode.js:1614
Parameters
  • newPosOrX Vec2 | Number X coordinate for position or the position (x, y) of the node in coordinates
  • y Number Y coordinate for position
Examples
node.setPosition(cc.v2(0, 0));
node.setPosition(0, 0);
getScale

Returns the scale factor of the node. Assertion will fail when _scaleX != _scaleY.

meta description
Returns Number
Defined in cocos2d/core/CCNode.js:1676
Examples
cc.log("Node Scale: " + node.getScale());
setScale

Sets the scale factor of the node. 1.0 is the default scale factor. This function can modify the X and Y scale at the same time.

meta description
Defined in cocos2d/core/CCNode.js:1692
Parameters
Examples
node.setScale(cc.v2(1, 1));
node.setScale(1, 1);
getContentSize

Returns a copy 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 by default.

meta description
Returns Size
Defined in cocos2d/core/CCNode.js:1722
Parameters
  • ignoreSizeProvider Boolean true if you need to get the original size of the node
Examples
cc.log("Content Size: " + node.getContentSize());
setContentSize

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.

meta description
Defined in cocos2d/core/CCNode.js:1745
Parameters
  • size Size | Number The untransformed size of the node or The untransformed size's width of the node.
  • height Number The untransformed size's height of the node.
Examples
node.setContentSize(cc.size(100, 100));
node.setContentSize(100, 100);
setOpacityModifyRGB

Set whether color should be changed with the opacity value, useless in ccsg.Node, but this function is override in some class to have such behavior.

meta description
Defined in cocos2d/core/CCNode.js:1789
Parameters
Examples
node.setOpacityModifyRGB(true);
isOpacityModifyRGB

Get whether color should be changed with the opacity value.

meta description
Returns Boolean
Defined in cocos2d/core/CCNode.js:1810
Examples
var hasChange = node.isOpacityModifyRGB();
getAnchorPoint

Returns a copy of the anchor point.
Anchor point 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 anchor point is (0.5,0.5), so it starts at the center of the node.

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:1872
Examples
cc.log("Node AnchorPoint: " + node.getAnchorPoint());
setAnchorPoint

Sets the anchor point in percent.
anchor point 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 anchor point is (0.5,0.5), so it starts at the center of the node.

meta description
Defined in cocos2d/core/CCNode.js:1896
Parameters
  • point Vec2 | Number The anchor point of node or The x axis anchor of node.
  • y Number The y axis anchor of node.
Examples
node.setAnchorPoint(cc.v2(1, 1));
node.setAnchorPoint(1, 1);
getAnchorPointInPoints

Returns a copy of the anchor point in absolute pixels.
you can only read it. If you wish to modify it, use setAnchorPoint.

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:1938
Examples
cc.log("AnchorPointInPoints: " + node.getAnchorPointInPoints());
getDisplayedOpacity

Returns the displayed opacity of Node, the difference between displayed opacity and opacity is that displayed opacity is calculated based on opacity and parent node's opacity when cascade opacity enabled.

meta description
Returns number
Defined in cocos2d/core/CCNode.js:1955
Examples
var displayOpacity = node.getDisplayedOpacity();
getDisplayedColor

Returns the displayed color of Node, the difference between displayed color and color is that displayed color is calculated based on color and parent node's color when cascade color enabled.

meta description
Returns Color
Defined in cocos2d/core/CCNode.js:1985
Examples
var displayColor = node.getDisplayedColor();
getNodeToParentTransformAR

Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
The matrix is in Pixels.
This method is AR (Anchor Relative).

meta description
Returns AffineTransform
Defined in cocos2d/core/CCNode.js:2003
Examples
var affineTransform = node.getNodeToParentTransformAR();
getBoundingBox

Returns a "local" axis aligned bounding box of the node.
The returned box is relative only to its parent.

meta description
Returns Rect
Defined in cocos2d/core/CCNode.js:2030
Examples
var boundingBox = node.getBoundingBox();
getBoundingBoxToWorld

Returns a "world" axis aligned bounding box of the node.
The bounding box contains self and active children's world bounding box.

meta description
Returns Rect
Defined in cocos2d/core/CCNode.js:2046
Examples
var newRect = node.getBoundingBoxToWorld();
getNodeToParentTransform

Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
The matrix is in Pixels.

meta description
Returns AffineTransform
Defined in cocos2d/core/CCNode.js:2091
Examples
var affineTransform = node.getNodeToParentTransform();
getNodeToWorldTransform

Returns the world affine transform matrix. The matrix is in Pixels.

meta description
Returns AffineTransform
Defined in cocos2d/core/CCNode.js:2114
Examples
var affineTransform = node.getNodeToWorldTransform();
getNodeToWorldTransformAR

Returns the world affine transform matrix. The matrix is in Pixels.
This method is AR (Anchor Relative).

meta description
Returns AffineTransform
Defined in cocos2d/core/CCNode.js:2143
Examples
var mat = node.getNodeToWorldTransformAR();
getParentToNodeTransform

Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
The matrix is in Pixels. The returned transform is readonly and cannot be changed.

meta description
Returns AffineTransform
Defined in cocos2d/core/CCNode.js:2174
Examples
var affineTransform = node.getParentToNodeTransform();
getWorldToNodeTransform

Returns the inverse world affine transform matrix. The matrix is in Pixels. 返回世界坐标系到节点坐标系的逆矩阵。

meta description
Returns AffineTransform
Defined in cocos2d/core/CCNode.js:2190
Examples
var affineTransform = node.getWorldToNodeTransform();
convertToNodeSpace

Converts a Point to node (local) space coordinates. The result is in Vec2.

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:2220
Parameters
Examples
var newVec2 = node.convertToNodeSpace(cc.v2(100, 100));
convertToWorldSpace

Converts a Point to world space coordinates. The result is in Points.

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:2238
Parameters
Examples
var newVec2 = node.convertToWorldSpace(cc.v2(100, 100));
convertToNodeSpaceAR

Converts a Point to node (local) space coordinates. The result is in Points.
treating the returned/received node point as anchor relative.

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:2257
Parameters
Examples
var newVec2 = node.convertToNodeSpaceAR(cc.v2(100, 100));
convertToWorldSpaceAR

Converts a local Point to world space coordinates.The result is in Points.
treating the returned/received node point as anchor relative.

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:2284
Parameters
Examples
var newVec2 = node.convertToWorldSpaceAR(cc.v2(100, 100));
convertTouchToNodeSpace

convenience methods which take a cc.Touch instead of cc.Vec2.

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:2311
Parameters
  • touch Touch The touch object
Examples
var newVec2 = node.convertTouchToNodeSpace(touch);
convertTouchToNodeSpaceAR

converts a cc.Touch (world coordinates) into a local coordinate. This method is AR (Anchor Relative).

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:2324
Parameters
  • touch Touch The touch object
Examples
var newVec2 = node.convertTouchToNodeSpaceAR(touch);
addChild

Adds a child to the node with z order and tag.

meta description
Defined in cocos2d/core/CCNode.js:2341
Parameters
  • child Node A child node
  • localZOrder Number Z order for drawing priority. Please refer to setZOrder(int)
  • tag Number | String An integer or a name to identify the node easily. Please refer to setTag(int) and setName(string)
Examples
node.addChild(newNode, 1, 1001);
cleanup

Stops all running actions and schedulers.

meta description
Defined in cocos2d/core/CCNode.js:2383
Examples
node.cleanup();
sortAllChildren

Sorts the children array depends on children's zIndex and arrivalOrder, normally you won't need to invoke this function.

meta description
Defined in cocos2d/core/CCNode.js:2405
getPositionX

Returns the x axis position of the node in cocos2d coordinates.

meta description
Returns Number
Defined in cocos2d/core/CCNode.js:2640
Examples
var posX = node.getPositionX();
setPositionX

Sets the x axis position of the node in cocos2d coordinates.

meta description
Defined in cocos2d/core/CCNode.js:2649
Parameters
Examples
node.setPositionX(1);
getPositionY

Returns the y axis position of the node in cocos2d coordinates.

meta description
Returns Number
Defined in cocos2d/core/CCNode.js:2658
Examples
var posY = node.getPositionY();
setPositionY

Sets the y axis position of the node in cocos2d coordinates.

meta description
Defined in cocos2d/core/CCNode.js:2667
Parameters
  • y Number The new position in y axis
Examples
node.setPositionY(100);
getLocalZOrder

Returns the local Z order of this node.

meta description
Returns Number
Defined in cocos2d/core/CCNode.js:2676
Examples
var localZorder = node.getLocalZOrder();
setLocalZOrder

LocalZOrder is the 'key' used to sort the node relative to its siblings.

The Node's parent will sort all its children based ont the LocalZOrder value.
If two nodes have the same LocalZOrder, then the node that was added first to the children's array
will be in front of the other node in the array.
Also, the Scene Graph is traversed using the "In-Order" tree traversal algorithm ( http://en.wikipedia.org/wiki/Tree_traversal#In-order )
And Nodes that have LocalZOder values smaller than 0 are the "left" subtree
While Nodes with LocalZOder greater than 0 are the "right" subtree.

meta description
Defined in cocos2d/core/CCNode.js:2685
Parameters
Examples
node.setLocalZOrder(1);
isCascadeOpacityEnabled

Returns whether node's opacity value affect its child nodes.

meta description
Returns Boolean
Defined in cocos2d/core/CCNode.js:2708
Examples
cc.log(node.isCascadeOpacityEnabled());
setCascadeOpacityEnabled

Enable or disable cascade opacity, if cascade enabled, child nodes' opacity will be the multiplication of parent opacity and its own opacity.

meta description
Defined in cocos2d/core/CCNode.js:2717
Parameters
Examples
node.setCascadeOpacityEnabled(true);
attr

Properties configuration function </br> All properties in attrs will be set to the node, </br> when the setter of the node is available, </br> the property will be set via setter function.</br>

meta description
Defined in cocos2d/core/utils/base-node.js:436
Parameters
  • attrs Object Properties to be set to node
Examples
var attrs = { key: 0, num: 100 };
node.attr(attrs);
getChildByTag

Returns a child from the container given its tag.

meta description
Returns Node
Defined in cocos2d/core/utils/base-node.js:455
Parameters
  • aTag Number An identifier to find the child node.
Examples
var child = node.getChildByTag(1001);
getChildByUuid

Returns a child from the container given its uuid.

meta description
Returns Node
Defined in cocos2d/core/utils/base-node.js:476
Parameters
  • uuid String The uuid to find the child node.
Examples
var child = node.getChildByUuid(uuid);
getChildByName

Returns a child from the container given its name.

meta description
Returns Node
Defined in cocos2d/core/utils/base-node.js:499
Parameters
  • name String A name to find the child node.
Examples
var child = node.getChildByName("Test Node");
insertChild

Inserts a child to the node at a specified index.

meta description
Defined in cocos2d/core/utils/base-node.js:537
Parameters
  • child Node the child node to be inserted
  • siblingIndex Number the sibling index to place the child in
Examples
node.insertChild(child, 2);
getSiblingIndex

Get the sibling index.

meta description
Returns number
Defined in cocos2d/core/utils/base-node.js:555
Examples
var index = node.getSiblingIndex();
setSiblingIndex

Set the sibling index of this node.

meta description
Defined in cocos2d/core/utils/base-node.js:572
Parameters
Examples
node.setSiblingIndex(1);
removeFromParent

Remove itself from its parent node. If cleanup is true, then also remove all events and actions.
If the cleanup parameter is not passed, it will force a cleanup, so it is recommended that you always pass in the false parameter when calling this API.
If the node orphan, then nothing happens.

meta description
Defined in cocos2d/core/utils/base-node.js:607
Parameters
  • cleanup Boolean true if all actions and callbacks on this node should be removed, false otherwise.
Examples
node.removeFromParent();
node.removeFromParent(false);
removeChild

Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter. </p> 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.

meta description
Defined in cocos2d/core/utils/base-node.js:631
Parameters
  • child Node The child node which will be removed.
  • cleanup Boolean true if all running actions and callbacks on the child node will be cleanup, false otherwise.
Examples
node.removeChild(newNode);
node.removeChild(newNode, false);
removeChildByTag

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.

meta description
Defined in cocos2d/core/utils/base-node.js:659
Parameters
  • tag Number An integer number that identifies a child node
  • cleanup Boolean true if all running actions and callbacks on the child node will be cleanup, false otherwise.
Examples
node.removeChildByTag(1001);
node.removeChildByTag(1001, false);
removeAllChildren

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.

meta description
Defined in cocos2d/core/utils/base-node.js:685
Parameters
  • cleanup Boolean true if all running actions on all children nodes should be cleanup, false otherwise.
Examples
node.removeAllChildren();
node.removeAllChildren(false);
isChildOf

Is this node a child of the given node?

meta description
Returns Boolean
Defined in cocos2d/core/utils/base-node.js:721
Parameters
Examples
node.isChildOf(newNode);
getComponent

Returns the component of supplied type if the node has one attached, null if it doesn't.
You can also get component in the node by passing in the name of the script.

meta description
Returns Component
Defined in cocos2d/core/utils/base-node.js:744
Parameters
Examples
// get sprite component.
var sprite = node.getComponent(cc.Sprite);
// get custom test calss.
var test = node.getComponent("Test");
getComponents

Returns all components of supplied type in the node.

meta description
Returns Component[]
Defined in cocos2d/core/utils/base-node.js:771
Parameters
Examples
var sprites = node.getComponents(cc.Sprite);
var tests = node.getComponents("Test");
getComponentInChildren

Returns the component of supplied type in any of its children using depth first search.

meta description
Returns Component
Defined in cocos2d/core/utils/base-node.js:792
Parameters
Examples
var sprite = node.getComponentInChildren(cc.Sprite);
var Test = node.getComponentInChildren("Test");
getComponentsInChildren

Returns all components of supplied type in self or any of its children.

meta description
Returns Component[]
Defined in cocos2d/core/utils/base-node.js:813
Parameters
Examples
var sprites = node.getComponentsInChildren(cc.Sprite);
var tests = node.getComponentsInChildren("Test");
addComponent

Adds a component class to the node. You can also add component to node by passing in the name of the script.

meta description
Returns Component
Defined in cocos2d/core/utils/base-node.js:849
Parameters
  • typeOrClassName Function | String The constructor or the class name of the component to add
Examples
var sprite = node.addComponent(cc.Sprite);
var test = node.addComponent("Test");
_addComponentAt

This api should only used by undo system

meta description
Defined in cocos2d/core/utils/base-node.js:937
Parameters
removeComponent

Removes a component identified by the given name or removes the component object given. You can also use component.destroy() if you already have the reference.

meta description
Defined in cocos2d/core/utils/base-node.js:983
Deprecated please destroy the component to remove it.
Parameters
Examples
node.removeComponent(cc.Sprite);
var Test = require("Test");
node.removeComponent(Test);
_getDependComponent
meta description
Returns Component
Defined in cocos2d/core/utils/base-node.js:1011
Parameters
destroyAllChildren

Destroy all children from the node, and release all their own references to other objects.
Actual destruct operation will delayed until before rendering.

meta description
Defined in cocos2d/core/utils/base-node.js:1075
Examples
node.destroyAllChildren();
once

Register an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.

meta description
Defined in cocos2d/core/event/event-target.js:352
Parameters
  • type String A string representing the event type to listen for.
  • callback Function The callback that will be invoked when the event is dispatched.
                           The callback is ignored if it is a duplicate (the callbacks are unique).
    
  • target Object The target (this object) to invoke the callback, can be null
  • useCapture Boolean When set to true, the capture argument prevents callback
                           from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE.
                           When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE.
                           Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.
    
Examples
node.once(cc.Node.EventType.TOUCH_END, function (event) {
    cc.log("this is callback");
}, node);
dispatchEvent

Dispatches an event into the event flow. The event target is the EventTarget object upon which the dispatchEvent() method is called.

meta description
Defined in cocos2d/core/event/event-target.js:397
Parameters
  • event Event The Event object that is dispatched into the event flow
emit

Send an event to this object directly, this method will not propagate the event to any other objects. The event will be created from the supplied message, you can get the "detail" argument from event.detail.

meta description
Defined in cocos2d/core/event/event-target.js:411
Parameters
  • message String the message to send
  • detail Any whatever argument the message needs
destroy

Destroy this Object, and release all its own references to other objects.
Actual object destruction will delayed until before rendering. From the next frame, this object is not usable any more. You can use cc.isValid(obj) to check whether the object is destroyed before accessing it.

meta description
Returns Boolean
Defined in cocos2d/core/platform/CCObject.js:296
Examples
obj.destroy();
_destruct

Clear all references in the instance.

NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject. You can override the _destruct method if you need, for example: _destruct: function () { for (var key in this) { if (this.hasOwnProperty(key)) { switch (typeof this[key]) { case 'string': this[key] = ''; break; case 'object': case 'function': this[key] = null; break; } } }

meta description
Defined in cocos2d/core/platform/CCObject.js:428
_onPreDestroy

Called before the object being destroyed.

meta description
Defined in cocos2d/core/platform/CCObject.js:461
_serialize

The customized serialization for this object. (Editor Only)

meta description
Returns object
Defined in cocos2d/core/platform/CCObject.js:486
Parameters
_deserialize

Init this object from the custom serialized data.

meta description
Defined in cocos2d/core/platform/CCObject.js:496
Parameters
  • data Object the serialized json data
  • ctx _Deserializer

Events

position-changed Event

Module: cc

Index

Details

size-changed Event

Module: cc

Index

Details

anchor-changed Event

Module: cc

Index

Details

child-added Event

Module: cc

Index

Details

child-removed Event

Module: cc

Index

Details

child-reorder Event

Module: cc

Index

Details

group-changed Event

Module: cc

Index

Details

touchstart Event

Module: cc

Index

Details

active-in-hierarchy-changed Event

Module: cc Parent Module: cc

Note: This event is only emitted from the top most node whose active value did changed, not including its child nodes.

Index

Details

results matching ""

    No results matching ""