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.
    Which Group this node belongs to will resolve that this node's collision components can collide with which other collision componentns.
  • group String Group of node.
    Which Group this node belongs to will resolve that this node's collision components can collide with which other collision componentns.
  • 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. Size provider can equals to this._sgNode.
  • 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. If false, the node will be destroyed automatically when loading a new scene. Default is false.
  • 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.
    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.
  • activeInHierarchy Boolean Indicates whether this node is active in the scene.
  • tag Number Tag of node.
  • __eventTargets EventTarget[] Register all related EventTargets, all event callbacks will be removed in _onPreDestroy
  • parent Node The parent of the node.
  • _name String
  • _objFlags Number
  • isValid Boolean Indicates whether the object is not yet destroyed.
Methods
  • constructor
  • 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.
  • off Removes the callback previously registered with the same type, callback, target and or useCapture. This method is merely an alias to removeEventListener.
  • targetOff Removes all callbacks previously registered with the same 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://docs.cocos2d-x.org/editors_and_tools/creator-chapters/scripting/internal-events/
  • 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/
  • 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.
  • pauseAllActions Pause all actions running on the current node. Equals to cc.director.getActionManager().pauseTarget(node).
  • resumeAllActions Resume all paused actions on the current node. Equals to cc.director.getActionManager().resumeTarget(node).
  • stopAllActions Stops and removes all actions from the running action list .
  • stopAction Stops and removes an action from the running action list.
  • stopActionByTag Removes an action from the running action list by its tag.
  • getActionByTag Returns an action from the running action list by its tag.
  • 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>
  • getPosition Returns a copy of the position (x, y) of the node in its parent's coordinates.
  • 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.
  • getScale Returns the scale factor of the node. Assertion will fail when _scaleX != _scaleY.
  • 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.
  • 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.
  • 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.
  • 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.
  • isOpacityModifyRGB Get whether color should be changed with the opacity value.
  • 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.
  • 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.
  • getAnchorPointInPoints Returns a copy of the anchor point in absolute pixels.
    you can only read it. If you wish to modify it, use setAnchorPoint.
  • 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.
  • 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.
  • 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).
  • getBoundingBox Returns a "local" axis aligned bounding box of the node.
    The returned box is relative only to its parent.
  • getBoundingBoxToWorld Returns a "world" axis aligned bounding box of the node.
    The bounding box contains self and active children's world bounding box.
  • getNodeToParentTransform Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
    The matrix is in Pixels.
  • getNodeToWorldTransform Returns the world affine transform matrix. The matrix is in Pixels.
  • getNodeToWorldTransformAR Returns the world affine transform matrix. The matrix is in Pixels.
    This method is AR (Anchor Relative).
  • 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.
  • getWorldToNodeTransform Returns the inverse world affine transform matrix. The matrix is in Pixels. 返回世界坐标系到节点坐标系的逆矩阵。
  • convertToNodeSpace Converts a Point to node (local) space coordinates. The result is in Vec2.
  • convertToWorldSpace Converts a Point to world space coordinates. The result is in Points.
  • convertToNodeSpaceAR Converts a Point to node (local) space coordinates. The result is in Points.
    treating the returned/received node point as anchor relative.
  • convertToWorldSpaceAR Converts a local Point to world space coordinates.The result is in Points.
    treating the returned/received node point as anchor relative.
  • convertTouchToNodeSpace convenience methods which take a cc.Touch instead of cc.Vec2.
  • convertTouchToNodeSpaceAR converts a cc.Touch (world coordinates) into a local coordinate. This method is AR (Anchor Relative).
  • addChild Adds a child to the node with z order and tag.
  • cleanup Stops all running actions and schedulers.
  • sortAllChildren Sorts the children array depends on children's zIndex and arrivalOrder, normally you won't need to invoke this function.
  • getPositionX Returns the x axis position of the node in cocos2d coordinates.
  • setPositionX Sets the x axis position of the node in cocos2d coordinates.
  • getPositionY Returns the y axis position of the node in cocos2d coordinates.
  • setPositionY Sets the y axis position of the node in cocos2d coordinates.
  • getLocalZOrder Returns the local Z order of this node.
  • setLocalZOrder LocalZOrder is the 'key' used to sort the node relative to its siblings.
                                                                                                            <br/>
    
    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.
  • isCascadeOpacityEnabled Returns whether node's opacity value affect its child nodes.
  • setCascadeOpacityEnabled Enable or disable cascade opacity, if cascade enabled, child nodes' opacity will be the multiplication of parent opacity and its own opacity.
  • 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>
  • getChildByTag Returns a child from the container given its tag.
  • getChildByUuid Returns a child from the container given its uuid.
  • getChildByName Returns a child from the container given its name.
  • insertChild Inserts a child to the node at a specified index.
  • getSiblingIndex Get the sibling index.
  • setSiblingIndex Set the sibling index of this node.
  • 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.
  • 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.
  • 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.
  • 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.
  • isChildOf Is this node a child of the given node?
  • 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.
  • getComponents Returns all components of supplied type in the node.
  • getComponentInChildren Returns the component of supplied type in any of its children using depth first search.
  • getComponentsInChildren Returns all components of supplied type in self or any of its children.
  • addComponent Adds a component class to the node. You can also add component to node by passing in the name of the script.
  • _addComponentAt This api should only used by undo system
  • 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.
  • _getDependComponent
  • destroyAllChildren Destroy all children from the node, and release all their own references to other objects.
    Actual destruct operation will delayed until before rendering.
  • once Register an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.
  • dispatchEvent Dispatches an event into the event flow. The event target is the EventTarget object upon which the dispatchEvent() method is called.
  • 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.
  • destroy Destroy this Object, and release all its own references to other objects.
    Actual object destruction will delayed until before rendering.
    After destroy, this CCObject is not usable any more. You can use cc.isValid(obj) to check whether the object is destroyed before accessing it.
  • _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; } } }

  • _onPreDestroy Called before the object being destroyed.
  • _serialize The customized serialization for this object. (Editor Only)
  • _deserialize Init this object from the custom serialized data.
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:399
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:415
position

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

meta description
Type Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:438
Examples
cc.log("Node Position: " + node.position);
x

x axis position of node.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:446
Examples
node.x = 100;
cc.log("Node Position X: " + node.x);
y

y axis position of node.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:489
Examples
node.y = 100;
cc.log("Node Position Y: " + node.y);
rotation

Rotation of node.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:532
Examples
node.rotation = 90;
cc.log("Node Rotation: " + node.rotation);
rotationX

Rotation on x axis.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:560
Examples
node.rotationX = 45;
cc.log("Node Rotation X: " + node.rotationX);
rotationY

Rotation on y axis.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:586
Examples
node.rotationY = 45;
cc.log("Node Rotation Y: " + node.rotationY);
scaleX

Scale on x axis.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:612
Examples
node.scaleX = 0.5;
cc.log("Node Scale X: " + node.scaleX);
scaleY

Scale on y axis.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:638
Examples
node.scaleY = 0.5;
cc.log("Node Scale Y: " + node.scaleY);
skewX

Skew x

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:664
Examples
node.skewX = 0;
cc.log("Node SkewX: " + node.skewX);
skewY

Skew y

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:683
Examples
node.skewY = 0;
cc.log("Node SkewY: " + node.skewY);
opacity

Opacity of node, default value is 255.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:702
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:729
Examples
cc.log("CascadeOpacity: " + node.cascadeOpacity);
color

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

meta description
Type Color
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:755
Examples
node.color = new cc.Color(255, 255, 255);
anchorX

Anchor point's position on x axis.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:780
Examples
node.anchorX = 0;
anchorY

Anchor point's position on y axis.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:805
Examples
node.anchorY = 0;
width

Width of node.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:830
Examples
node.width = 100;
height

Height of node.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:869
Examples
node.height = 100;
zIndex

Z order in depth which stands for the drawing order.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:908
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:942
_sizeProvider

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

meta description
Type _ccsg.Node
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:965
scale

The local scale relative to the parent.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2629
Examples
node.scale = 1;
_components
meta description
Type Component[]
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:133
_prefab

The PrefabInfo object

meta description
Type PrefabInfo
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:142
_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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:150
name

Name of node.

meta description
Type String
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:174
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:201
Examples
cc.log("Node Uuid: " + node.uuid);
children

All children nodes.

meta description
Type Node[]
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:220
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:238
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:254
Examples
node.active = false;
activeInHierarchy

Indicates whether this node is active in the scene.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:288
Examples
cc.log("activeInHierarchy: " + node.activeInHierarchy);
tag

Tag of node.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:302
Examples
node.tag = 1001;
__eventTargets

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

meta description
Type EventTarget[]
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:324
parent

The parent of the node.

meta description
Type Node
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:342
Examples
node.parent = newNode;
_name
meta description
Type String
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:50
_objFlags
meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:57
isValid

Indicates whether the object is not yet destroyed.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:225
Examples
cc.log(obj.isValid);

Methods

constructor
meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:936
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1169
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1254
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1283
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://docs.cocos2d-x.org/editors_and_tools/creator-chapters/scripting/internal-events/

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1298
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1314
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1452
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1487
Examples
node.pauseAllActions();
resumeAllActions

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

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1498
Examples
node.resumeAllActions();
stopAllActions

Stops and removes all actions from the running action list .

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1509
Examples
node.stopAllActions();
stopAction

Stops and removes an action from the running action list.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1520
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1533
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1549
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1569
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1614
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1626
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1688
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1704
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1734
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1757
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1801
Parameters
Examples
node.setOpacityModifyRGB(true);
isOpacityModifyRGB

Get whether color should be changed with the opacity value.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1822
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1884
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1908
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1950
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1967
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:1997
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2015
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2042
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2058
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2103
Examples
var affineTransform = node.getNodeToParentTransform();
getNodeToWorldTransform

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

meta description
Returns AffineTransform
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2126
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2155
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2186
Examples
var affineTransform = node.getParentToNodeTransform();
getWorldToNodeTransform

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

meta description
Returns AffineTransform
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2202
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2232
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2250
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2269
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2296
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2323
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2336
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2353
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2395
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2417
getPositionX

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

meta description
Returns Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2638
Examples
var posX = node.getPositionX();
setPositionX

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

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2647
Parameters
Examples
node.setPositionX(1);
getPositionY

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

meta description
Returns Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2656
Examples
var posY = node.getPositionY();
setPositionY

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

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2665
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2674
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2683
Parameters
Examples
node.setLocalZOrder(1);
isCascadeOpacityEnabled

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

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2706
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/CCNode.js:2715
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:407
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:426
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:447
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:470
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:508
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:526
Examples
var index = node.getSiblingIndex();
setSiblingIndex

Set the sibling index of this node.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:543
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:574
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:598
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:626
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:652
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:688
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:711
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:738
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:759
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:780
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:816
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:904
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:950
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:978
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/utils/base-node.js:1042
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/event-target.js:351
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/event-target.js:396
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event/event-target.js:410
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.
After destroy, this CCObject 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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:246
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:379
_onPreDestroy

Called before the object being destroyed.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:412
_serialize

The customized serialization for this object. (Editor Only)

meta description
Returns object
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:437
Parameters
_deserialize

Init this object from the custom serialized data.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:447
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 ""