Cocos Creator API

1.3.0

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

Scene

: cc

cc.Scene is a subclass of cc.Node that is used only as an abstract concept.
cc.Scene and cc.Node are almost identical with the difference that users can not modify cc.Scene manually.

autoReleaseAssets Boolean

Indicates whether all (directly or indirectly) static referenced assets of this scene are releasable by default after scene unloading.

name String

Name of node.

:

node.name = "New Node";
cc.log("Node Name: " + node.name);

parent Node

The parent of the node.

:

node.parent = newNode;

uuid String readOnly

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

:

cc.log("Node Uuid: " + node.uuid);

skewX Number

Skew x

:

node.skewX = 0;
cc.log("Node SkewX: " + node.skewX);

skewY Number

Skew y

:

node.skewY = 0;
cc.log("Node SkewY: " + node.skewY);

zIndex Number

Z order in depth which stands for the drawing order.

:

node.zIndex = 1;
cc.log("Node zIndex: " + node.zIndex);

rotation Number

Rotation of node.

:

node.rotation = 90;
cc.log("Node Rotation: " + node.rotation);

rotationX Number

Rotation on x axis.

:

node.rotationX = 45;
cc.log("Node Rotation X: " + node.rotationX);

rotationY Number

Rotation on y axis.

:

node.rotationY = 45;
cc.log("Node Rotation Y: " + node.rotationY);

scaleX Number

Scale on x axis.

:

node.scaleX = 0.5;
cc.log("Node Scale X: " + node.scaleX);

scaleY Number

Scale on y axis.

:

node.scaleY = 0.5;
cc.log("Node Scale Y: " + node.scaleY);

x Number

x axis position of node.

:

node.x = 100;
cc.log("Node Position X: " + node.x);

y Number

y axis position of node.

:

node.y = 100;
cc.log("Node Position Y: " + node.y);

children Node[] readOnly

All children nodes.

:

var children = node.children;
for (var i = 0; i < children.length; ++i) {
    cc.log("Node: " + children[i]);
}

childrenCount Number readOnly

All children nodes.

:

var count = node.childrenCount;
cc.log("Node Children Count: " + count);

anchorX Number

Anchor point's position on x axis.

:

node.anchorX = 0;

anchorY Number

Anchor point's position on y axis.

:

node.anchorY = 0;

width Number

Width of node.

:

node.width = 100;

height Number

Height of node.

:

node.height = 100;

_ignoreAnchor Boolean private

Indicate whether ignore the anchor point property for positioning.

tag Number

Tag of node.

:

node.tag = 1001;

opacity Number

Opacity of node, default value is 255.

:

node.opacity = 255;

cascadeOpacity Boolean

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

:

cc.log("CascadeOpacity: " + node.cascadeOpacity);

color Color

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

:

node.color = new cc.Color(255, 255, 255);

_sgNode _ccsg.Node private

Current scene graph node for this node.

_sizeProvider _ccsg.Node private

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

__eventTargets EventTarget[] private

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

scale Number

The local scale relative to the parent.

:

node.scale = 1;

_name String private

_objFlags Number private

isValid Boolean readOnly

Indicates whether the object is not yet destroyed.

:

cc.log(obj.isValid);

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

attr
(
  • attrs
)

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.

attrs Object

Properties to be set to node

:

var attrs = { key: 0, num: 100 };
node.attr(attrs);

getScale ( ) Number

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

:

: Number

The scale factor

:

cc.log("Node Scale: " + node.getScale());

setScale
(
  • scaleX
  • [scaleY =scale]
)

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.

scaleX Number | Vec2

scaleX or scale

scaleY optional Number scale

:

node.setScale(cc.v2(1, 1));
node.setScale(1, 1);

getPosition ( ) Vec2

Returns a copy of the position (x,y) of the node in cocos2d coordinates. (0,0) is the left-bottom corner.

:

: Vec2

The position (x,y) of the node in OpenGL coordinates

:

cc.log("Node Position: " + node.getPosition());

setPosition
(
  • newPosOrxValue
  • [yValue ]
)

Changes the position (x,y) of the node in cocos2d coordinates.
The original point (0,0) is at the left-bottom corner of screen.
Usually we use cc.v2(x,y) to compose CCVec2 object.
and Passing two numbers (x,y) is more efficient than passing CCPoint object.

newPosOrxValue Vec2 | Number

The position (x,y) of the node in coordinates or the X coordinate for position

yValue optional Number

Y coordinate for position

:

node.setPosition(cc.v2(0, 0));
node.setPosition(0, 0);

getAnchorPoint ( ) Vec2

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.

:

: Vec2

The anchor point of node.

:

cc.log("Node AnchorPoint: " + node.getAnchorPoint());

setAnchorPoint
(
  • point
  • [y ]
)

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.

point Vec2 | Number

The anchor point of node or The x axis anchor of node.

y optional Number

The y axis anchor of node.

:

node.setAnchorPoint(cc.v2(1, 1));
node.setAnchorPoint(1, 1);

getAnchorPointInPoints ( ) Vec2

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

:

: Vec2

The anchor point in absolute pixels.

:

cc.log("AnchorPointInPoints: " + node.getAnchorPointInPoints());

getContentSize
(
  • [ignoreSizeProvider =false]
)
Size

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.

ignoreSizeProvider optional Boolean false

true if you need to get the original size of the node

:

: Size

The untransformed size of the node.

:

cc.log("Content Size: " + node.getContentSize());

setContentSize
(
  • size
  • [height ]
)

Sets the untransformed size of the node.
The contentSize remains the same no matter the node is scaled or rotated.
All nodes has a size. Layer and Scene has the same size of the screen.

size Size | Number

The untransformed size of the node or The untransformed size's width of the node.

height optional Number

The untransformed size's height of the node.

:

node.setContentSize(cc.size(100, 100));
node.setContentSize(100, 100);

getBoundingBox ( ) Rect

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

:

: Rect

The calculated bounding box of the node

:

var boundingBox = node.getBoundingBox();

cleanup ( )

Stops all running actions and schedulers.

:

node.cleanup();

getChildByTag
(
  • aTag
)
Node

Returns a child from the container given its tag.

aTag Number

An identifier to find the child node.

:

: Node

a CCNode object whose tag equals to the input parameter

:

var child = node.getChildByTag(1001);

getChildByUuid
(
  • uuid
)
Node

Returns a child from the container given its uuid.

uuid String

The uuid to find the child node.

:

: Node

a Node whose uuid equals to the input parameter

:

var child = node.getChildByUuid(uuid);

getChildByName
(
  • name
)
Node

Returns a child from the container given its name.

name String

A name to find the child node.

:

: Node

a CCNode object whose name equals to the input parameter

:

var child = node.getChildByName("Test Node");

addChild
(
  • child
  • [localZOrder ]
  • [tag ]
)

"add" logic MUST only be in this method

child Node

A child node

localZOrder optional Number

Z order for drawing priority. Please refer to setZOrder(int)

tag optional Number | String

An integer or a name to identify the node easily. Please refer to setTag(int) and setName(string)

:

node.addChild(newNode, 1, 1001);

removeFromParent
(
  • [cleanup =true]
)

Remove itself from its parent node. If cleanup is true, then also remove all actions and callbacks.
If the cleanup parameter is not passed, it will force a cleanup.
If the node orphan, then nothing happens.

cleanup optional Boolean true

true if all actions and callbacks on this node should be removed, false otherwise.

:

node.removeFromParent();
node.removeFromParent(false);

removeChild
(
  • child
  • [cleanup =true]
)

Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.

If the cleanup parameter is not passed, it will force a cleanup.
"remove" logic MUST only be on this method
If a class wants to extend the 'removeChild' behavior it only needs
to override this method.

child Node

The child node which will be removed.

cleanup optional Boolean true

true if all running actions and callbacks on the child node will be cleanup, false otherwise.

:

node.removeChild(newNode);
node.removeChild(newNode, false);

removeChildByTag
(
  • tag
  • [cleanup =true]
)

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.

tag Number

An integer number that identifies a child node

cleanup optional Boolean true

true if all running actions and callbacks on the child node will be cleanup, false otherwise.

:

node.removeChildByTag(1001);
node.removeChildByTag(1001, false);

removeAllChildren
(
  • [cleanup =true]
)

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.

cleanup optional Boolean true

true if all running actions on all children nodes should be cleanup, false otherwise.

:

node.removeAllChildren();
node.removeAllChildren(false);

getParentToNodeTransform ( ) AffineTransform

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.

:

var affineTransform = node.getParentToNodeTransform();

getNodeToWorldTransform ( ) AffineTransform

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

:

var affineTransform = node.getNodeToWorldTransform();

getNodeToWorldTransformAR ( ) AffineTransform

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

:

var mat = node.getNodeToWorldTransformAR();

getWorldToNodeTransform ( ) AffineTransform

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

:

var affineTransform = node.getWorldToNodeTransform();

convertToNodeSpace
(
  • worldPoint
)
Vec2

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

worldPoint Vec2

:

: Vec2

:

var newVec2 = node.convertToNodeSpace(cc.v2(100, 100));

convertToWorldSpace
(
  • nodePoint
)
Vec2

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

nodePoint Vec2

:

: Vec2

:

var newVec2 = node.convertToWorldSpace(cc.v2(100, 100));

convertToNodeSpaceAR
(
  • worldPoint
)
Vec2

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

worldPoint Vec2

:

: Vec2

:

var newVec2 = node.convertToNodeSpaceAR(cc.v2(100, 100));

convertToWorldSpaceAR
(
  • nodePoint
)
Vec2

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

nodePoint Vec2

:

: Vec2

:

var newVec2 = node.convertToWorldSpaceAR(cc.v2(100, 100));

convertTouchToNodeSpace
(
  • touch
)
Vec2

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

touch Touch

The touch object

:

: Vec2

:

var newVec2 = node.convertTouchToNodeSpace(touch);

convertTouchToNodeSpaceAR
(
  • touch
)
Vec2

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

touch Touch

The touch object

:

: Vec2

:

var newVec2 = node.convertTouchToNodeSpaceAR(touch);

getNodeToParentTransform ( ) AffineTransform

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

:

: AffineTransform

The affine transform object

:

var affineTransform = node.getNodeToParentTransform();

getNodeToParentTransformAR ( ) AffineTransform

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).

:

: AffineTransform

The affine transform object

:

var affineTransform = node.getNodeToParentTransformAR();

getBoundingBoxToWorld ( ) Rect

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

:

: Rect

:

var newRect = node.getBoundingBoxToWorld();

getDisplayedOpacity ( ) number

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.

:

: number

displayed opacity

:

var displayOpacity = node.getDisplayedOpacity();

getDisplayedColor ( ) Color

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.

:

: Color

:

var displayColor = node.getDisplayedColor();

setOpacityModifyRGB
(
  • opacityValue
)

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.

opacityValue Boolean

:

node.setOpacityModifyRGB(true);

isOpacityModifyRGB ( ) Boolean

Get whether color should be changed with the opacity value.

:

:

var hasChange = node.isOpacityModifyRGB();

getSiblingIndex ( ) number

Get the sibling index.

:

: number

:

var index = node.getSiblingIndex();

setSiblingIndex
(
  • index
)

Set the sibling index of this node.

index Number

:

node.setSiblingIndex(1);

isChildOf
(
  • parent
)
Boolean

Is this node a child of the given node?

parent Node

:

: Boolean

Returns true if this node is a child, deep child or identical to the given node.

:

node.isChildOf(newNode);

sortAllChildren ( )

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

getPositionX ( ) Number

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

:

: Number

x - The new position in x axis

:

var posX = node.getPositionX();

setPositionX
(
  • x
)

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

x Number

:

node.setPositionX(1);

getPositionY ( ) Number

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

:

: Number

:

var posY = node.getPositionY();

setPositionY
(
  • y
)

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

y Number

The new position in y axis

:

node.setPositionY(100);

getLocalZOrder ( ) Number

Returns the local Z order of this node.

:

: Number

The local (relative to its siblings) Z order.

:

var localZorder = node.getLocalZOrder();

setLocalZOrder
(
  • localZOrder
)

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.

localZOrder Number

:

node.setLocalZOrder(1);

isCascadeOpacityEnabled ( ) Boolean

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

:

:

cc.log(node.isCascadeOpacityEnabled());

setCascadeOpacityEnabled
(
  • cascadeOpacityEnabled
)

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

cascadeOpacityEnabled Boolean

:

node.setCascadeOpacityEnabled(true);

setCascadeColorEnabled
(
  • cascadeColorEnabled
)

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

cascadeColorEnabled Boolean

:

node.setCascadeColorEnabled(true);

destroy ( ) Boolean

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.

:

: Boolean

whether it is the first time the destroy being called

:

obj.destroy();

_destruct ( ) private

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.

_onPreDestroy ( ) private

Called before the object being destroyed.

_serialize
(
  • exporting
)
object private

The customized serialization for this object. (Editor Only)

exporting Boolean

:

: object

the serialized json data object

_deserialize
(
  • data
  • ctx
)
private

Init this object from the custom serialized data.

data Object

the serialized json data

ctx _Deserializer

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index