Node Class

Extends _BaseNode

Defined in: https://github.com/cocos-creator/engine/blob/8bf4522a6d43b53258219983aabd728909ce24ca/cocos2d/core/CCNode.js:537

Module: cc

Class of all entities in Cocos Creator scenes.
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.
  • scale Number The local scale relative to the parent.
  • 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.
  • 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 Node's order in children list will affect its rendering order.
  • cascadeOpacity Boolean Cascade opacity is removed from v2.0
  • _level Number
  • _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.
  • __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
  • position-changed The position changing event, you can listen to this event through the statement this.node.on(cc.Node.EventType.POSITION_CHANGED, callback, this);
  • size-changed The size changing event, you can listen to this event through the statement this.node.on(cc.Node.EventType.SIZE_CHANGED, callback, this);
  • anchor-changed The anchor changing event, you can listen to this event through the statement this.node.on(cc.Node.EventType.ANCHOR_CHANGED, callback, this);
  • child-added The adding child event, you can listen to this event through the statement this.node.on(cc.Node.EventType.CHILD_ADDED, callback, this);
  • child-removed The removing child event, you can listen to this event through the statement this.node.on(cc.Node.EventType.CHILD_REMOVED, callback, this);
  • child-reorder The reordering child event, you can listen to this event through the statement this.node.on(cc.Node.EventType.CHILD_REORDER, callback, this);
  • group-changed The group changing event, you can listen to this event through the statement this.node.on(cc.Node.EventType.GROUP_CHANGED, callback, this);
  • active-in-hierarchy-changed Note: This event is only emitted from the top most node whose active value did changed,...

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:584
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:600
position

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

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

x axis position of node.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:633
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:676
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:742
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:770
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:803
Examples
node.rotationY = 45;
cc.log("Node Rotation Y: " + node.rotationY);
scale

The local scale relative to the parent.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:836
Examples
node.scale = 1;
scaleX

Scale on x axis.

meta description
Type Number
Defined in cocos2d/core/CCNode.js:845
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:871
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:897
Examples
node.skewX = 0;
cc.log("Node SkewX: " + node.skewX);
skewY

Skew y

meta description
Type Number
Defined in cocos2d/core/CCNode.js:917
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:937
Examples
node.opacity = 255;
color

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

meta description
Type Color
Defined in cocos2d/core/CCNode.js:959
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:989
Examples
node.anchorX = 0;
anchorY

Anchor point's position on y axis.

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

Width of node.

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

Height of node.

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

zIndex is the 'key' used to sort the node relative to its siblings.
The value of zIndex should be in the range between cc.macro.MIN_ZINDEX and cc.macro.MAX_ZINDEX.
The Node's parent will sort all its children based on the zIndex value and the arrival order.
Nodes with greater zIndex will be sorted after nodes with smaller zIndex.
If two nodes have the same zIndex, then the node that was added first to the children's array will be in front of the other node in the array.
Node's order in children list will affect its rendering order. Parent is always rendering before all children.

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

Cascade opacity is removed from v2.0 Indicate whether node's opacity value affect its child nodes, default value is true.

meta description
Type Boolean
Defined in cocos2d/core/CCNode.js:3189
Deprecated since v2.0
_level
meta description
Type Number
Defined in cocos2d/core/utils/base-node.js:151
_components
meta description
Type Component[]
Defined in cocos2d/core/utils/base-node.js:159
_prefab

The PrefabInfo object

meta description
Type PrefabInfo
Defined in cocos2d/core/utils/base-node.js:168
_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:176
name

Name of node.

meta description
Type String
Defined in cocos2d/core/utils/base-node.js:200
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:222
Examples
cc.log("Node Uuid: " + node.uuid);
children

All children nodes.

meta description
Type Node[]
Defined in cocos2d/core/utils/base-node.js:237
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:255
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:271
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:305
Examples
cc.log("activeInHierarchy: " + node.activeInHierarchy);
__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:331
parent

The parent of the node.

meta description
Type Node
Defined in cocos2d/core/utils/base-node.js:342
Examples
cc.log("Node Parent: " + node.parent);
_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:1137
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,
These kinds of event are triggered with dispatchEvent, the dispatch process has three steps:

  1. Capturing phase: dispatch in capture targets (_getCapturingTargets), e.g. parents in node tree, from root to the real target
  2. At target phase: dispatch to the listeners of the real target
  3. Bubbling phase: dispatch in bubble targets (_getBubblingTargets), e.g. parents in node tree, from the real target to root
    In any moment of the dispatching process, it can be stopped via event.stopPropagation() or event.stopPropagationImmidiate().
    It's the recommended way to register touch/mouse event for Node,
    please do not use cc.eventManager directly for Node.
    You can also register custom event and use emit to trigger custom event on Node.
    For such events, there won't be capturing and bubbling phase, your event will be dispatched directly to its listeners registered on the same node.
    You can also pass event callback parameters with emit by passing parameters after type.
meta description
Returns Function
Defined in cocos2d/core/CCNode.js:1441
Parameters
  • type String | Node.EventType A string representing the event type to listen for.
    See Node/EventTyupe/POSITION_CHANGED 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).
    • event Event | Any event or first argument when emit
    • arg2 Any arg2
    • arg3 Any arg3
    • arg4 Any arg4
    • arg5 Any arg5
  • target Object The target (this object) to invoke the callback, can be null
  • useCapture Boolean When set to true, the listener will be triggered at capturing phase which is ahead of the final target emit, otherwise it will be triggered during bubbling phase.
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.on(cc.Node.EventType.TOUCH_MOVE, callback, this);
node.on(cc.Node.EventType.TOUCH_END, callback, this);
node.on(cc.Node.EventType.TOUCH_CANCEL, callback, this);
node.on(cc.Node.EventType.ANCHOR_CHANGED, callback);
node.on(cc.Node.EventType.COLOR_CHANGED, callback);
once

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

meta description
Defined in cocos2d/core/CCNode.js:1520
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).
    
    • event Event | Any event or first argument when emit
    • arg2 Any arg2
    • arg3 Any arg3
    • arg4 Any arg4
    • arg5 Any arg5
  • target Object The target (this object) to invoke the callback, can be null
Examples
node.once(cc.Node.EventType.ANCHOR_CHANGED, callback);
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:1597
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 When set to true, the listener will be triggered at capturing phase which is ahead of the final target emit, otherwise it will be triggered during bubbling phase.
Examples
this.node.off(cc.Node.EventType.TOUCH_START, this.memberFunction, this);
node.off(cc.Node.EventType.TOUCH_START, callback, this.node);
node.off(cc.Node.EventType.ANCHOR_CHANGED, callback, this);
targetOff

Removes all callbacks previously registered with the same target.

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

Checks whether the EventTarget object has any callback registered for a specific type of event.

meta description
Returns Boolean
Defined in cocos2d/core/CCNode.js:1732
Parameters
  • type String The type of event.
emit

Trigger an event directly with the event name and necessary arguments.

meta description
Defined in cocos2d/core/CCNode.js:1750
Parameters
  • type String event type
  • arg1 Any First argument in callback
  • arg2 Any Second argument in callback
  • arg3 Any Third argument in callback
  • arg4 Any Fourth argument in callback
  • arg5 Any Fifth argument in callback
Examples
eventTarget.emit('fire', event);
eventTarget.emit('fire', message, emitter);
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/CCNode.js:1774
Parameters
  • event Event The Event object that is dispatched into the event flow
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://docs.cocos2d-x.org/editors_and_tools/creator-chapters/scripting/internal-events/

meta description
Defined in cocos2d/core/CCNode.js:1788
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://docs.cocos2d-x.org/editors_and_tools/creator-chapters/scripting/internal-events/

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

Get all the targets listening to the supplied type of event in the target's capturing phase. The capturing phase comprises the journey from the root to the last node BEFORE the event target's node. The result should save in the array parameter, and MUST SORT from child nodes to parent nodes.

Subclasses can override this method to make event propagable.

meta description
Defined in cocos2d/core/CCNode.js:1866
Parameters
  • type String the event type
  • array Array the array to receive targets
Examples
----------
Subclasses can override this method to make event propagable
```js
for (var target = this._parent; target; target = target._parent) {
    if (target._capturingListeners && target._capturingListeners.hasEventListener(type)) {
        array.push(target);
    }
}
_getBubblingTargets

Get all the targets listening to the supplied type of event in the target's bubbling phase. The bubbling phase comprises any SUBSEQUENT nodes encountered on the return trip to the root of the tree. The result should save in the array parameter, and MUST SORT from child nodes to parent nodes.

Subclasses can override this method to make event propagable.

meta description
Defined in cocos2d/core/CCNode.js:1888
Parameters
  • type String the event type
  • array Array the array to receive targets
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:1910
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:1939
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:1950
Examples
node.resumeAllActions();
stopAllActions

Stops and removes all actions from the running action list .

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

Stops and removes an action from the running action list.

meta description
Defined in cocos2d/core/CCNode.js:1972
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:1985
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:2001
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:2021
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:2047
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:2059
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 scale x != scale y.

meta description
Returns Number
Defined in cocos2d/core/CCNode.js:2119
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:2135
Parameters
Examples
node.setScale(cc.v2(1, 1));
node.setScale(1);
setRotation

Set rotation of node (along z axi).

meta description
Defined in cocos2d/core/CCNode.js:2165
Parameters
  • rotation Number Degree rotation value
getRotation

Get rotation of node (along z axi).

meta description
Defined in cocos2d/core/CCNode.js:2172
Parameters
  • rotation Number Degree rotation value
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:2179
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:2194
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);
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:2237
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:2261
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);
lookAt

Set rotation by lookAt target point, normally used by Camera Node

meta description
Defined in cocos2d/core/CCNode.js:2439
Parameters
getLocalMatrix

Get the local transform matrix (4x4), based on parent node coordinates

meta description
Returns Mat4
Defined in cocos2d/core/CCNode.js:2582
Parameters
  • out Mat4 The matrix object to be filled with data
Examples
let mat4 = cc.mat4();
node.getLocalMatrix(mat4);
getWorldMatrix

Get the world transform matrix (4x4)

meta description
Returns Mat4
Defined in cocos2d/core/CCNode.js:2598
Parameters
  • out Mat4 The matrix object to be filled with data
Examples
let mat4 = cc.mat4();
node.getWorldMatrix(mat4);
convertToNodeSpace

Converts a Point to node (local) space coordinates then add the anchor point position. So the return position will be related to the left bottom corner of the node's bounding box. This equals to the API behavior of cocos2d-x, you probably want to use convertToNodeSpaceAR instead

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

Converts a Point related to the left bottom corner of the node's bounding box to world space coordinates. This equals to the API behavior of cocos2d-x, you probably want to use convertToWorldSpaceAR instead

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

Converts a Point to node (local) space coordinates in which the anchor point is the origin position.

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

Converts a Point in node coordinates to world space coordinates.

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:2675
Parameters
Examples
var newVec2 = node.convertToWorldSpaceAR(cc.v2(100, 100));
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:2693
Deprecated since v2.0
Parameters
Examples
let affineTransform = cc.AffineTransform.create();
node.getNodeToParentTransform(affineTransform);
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:2721
Deprecated since v2.0
Parameters
Examples
let affineTransform = cc.AffineTransform.create();
node.getNodeToParentTransformAR(affineTransform);
getNodeToWorldTransform

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

meta description
Returns AffineTransform
Defined in cocos2d/core/CCNode.js:2746
Deprecated since v2.0
Parameters
Examples
let affineTransform = cc.AffineTransform.create();
node.getNodeToWorldTransform(affineTransform);
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:2773
Deprecated since v2.0
Parameters
Examples
let affineTransform = cc.AffineTransform.create();
node.getNodeToWorldTransformAR(affineTransform);
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:2796
Deprecated since v2.0
Parameters
Examples
let affineTransform = cc.AffineTransform.create();
node.getParentToNodeTransform(affineTransform);
getWorldToNodeTransform

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

meta description
Returns AffineTransform
Defined in cocos2d/core/CCNode.js:2820
Deprecated since v2.0
Parameters
Examples
let affineTransform = cc.AffineTransform.create();
node.getWorldToNodeTransform(affineTransform);
convertTouchToNodeSpace

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

meta description
Returns Vec2
Defined in cocos2d/core/CCNode.js:2840
Deprecated since v2.0
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:2854
Deprecated since v2.0
Parameters
  • touch Touch The touch object
Examples
var newVec2 = node.convertTouchToNodeSpaceAR(touch);
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:2868
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:2890
Examples
var newRect = node.getBoundingBoxToWorld();
addChild

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

meta description
Defined in cocos2d/core/CCNode.js:2956
Parameters
  • child Node A child node
  • zIndex Number Z order for drawing priority. Please refer to zIndex property
  • name String A name to identify the node easily. Please refer to name property
Examples
node.addChild(newNode, 1, "node");
cleanup

Stops all running actions and schedulers.

meta description
Defined in cocos2d/core/CCNode.js:2986
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:3008
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:3161
Deprecated since v2.0, please use opacity property, cascade opacity is removed
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:3175
Deprecated since v2.0, please use color property, cascade color is removed
isCascadeOpacityEnabled

Cascade opacity is removed from v2.0 Returns whether node's opacity value affect its child nodes.

meta description
Returns Boolean
Defined in cocos2d/core/CCNode.js:3199
Deprecated since v2.0
setCascadeOpacityEnabled

Cascade opacity is removed from v2.0 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:3209
Deprecated since v2.0
Parameters
setOpacityModifyRGB

Opacity modify RGB have been removed since v2.0 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:3219
Deprecated since v2.0
Parameters
isOpacityModifyRGB

Opacity modify RGB have been removed since v2.0 Get whether color should be changed with the opacity value.

meta description
Returns Boolean
Defined in cocos2d/core/CCNode.js:3230
Deprecated since v2.0
getParent

Get parent of the node.

meta description
Returns Node
Defined in cocos2d/core/utils/base-node.js:350
Examples
var parent = this.node.getParent();
setParent

Set parent of the node.

meta description
Defined in cocos2d/core/utils/base-node.js:362
Parameters
Examples
node.setParent(newNode);
attr

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

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

Returns a child from the container given its uuid.

meta description
Returns Node
Defined in cocos2d/core/utils/base-node.js:438
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:461
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:499
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:517
Examples
var index = node.getSiblingIndex();
setSiblingIndex

Set the sibling index of this node.

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

Walk though the sub children tree of the current node. Each node, including the current node, in the sub tree will be visited two times, before all children and after all children. This function call is not recursive, it's based on stack. Please don't walk any other node inside the walk process.

meta description
Defined in cocos2d/core/utils/base-node.js:565
Parameters
  • prefunc Function The callback to process node when reach the node for the first time
  • postfunc Function The callback to process node when re-visit the node after walked all children in its sub tree
Examples
node.walk(function (target) {
    console.log('Walked through node ' + target.name + ' for the first time');
}, function (target) {
    console.log('Walked through node ' + target.name + ' after walked all children in its sub tree');
});
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:679
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:703
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);
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:731
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:762
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:785
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:812
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:833
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:854
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:890
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:979
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:1027
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:1055
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:1101
Examples
node.destroyAllChildren();
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:430
_onPreDestroy

Called before the object being destroyed.

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

The customized serialization for this object. (Editor Only)

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

Init this object from the custom serialized data.

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

Events

position-changed Event

Module: cc

The position changing event, you can listen to this event through the statement this.node.on(cc.Node.EventType.POSITION_CHANGED, callback, this);

Index

Details

size-changed Event

Module: cc

The size changing event, you can listen to this event through the statement this.node.on(cc.Node.EventType.SIZE_CHANGED, callback, this);

Index

Details

anchor-changed Event

Module: cc

The anchor changing event, you can listen to this event through the statement this.node.on(cc.Node.EventType.ANCHOR_CHANGED, callback, this);

Index

Details

child-added Event

Module: cc

The adding child event, you can listen to this event through the statement this.node.on(cc.Node.EventType.CHILD_ADDED, callback, this);

Index

Details

child-removed Event

Module: cc

The removing child event, you can listen to this event through the statement this.node.on(cc.Node.EventType.CHILD_REMOVED, callback, this);

Index

Details

child-reorder Event

Module: cc

The reordering child event, you can listen to this event through the statement this.node.on(cc.Node.EventType.CHILD_REORDER, callback, this);

Index

Details

group-changed Event

Module: cc

The group changing event, you can listen to this event through the statement this.node.on(cc.Node.EventType.GROUP_CHANGED, callback, this);

Index

Details

active-in-hierarchy-changed Event

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 ""