cc
Module
The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace.
Classes
Enums
Index
Properties
ENGINE_VERSION
String
The current version of Cocos2d being used....
director
Director
Director
game
Game
This is a Game instance.
systemEvent
SystemEvent
The System event singleton for global usage
srcBlendFactor
macro.BlendFactor
specify the source Blend Factor, this will generate a custom material object, please pay attention to the memory cost.
dstBlendFactor
macro.BlendFactor
specify the destination Blend Factor.
view
View
cc.view is the shared view object.
winSize
Size
cc.winSize is the alias object for the size of the current game window.
Integer
string
Specify that the input value must be integer in Inspector.
Float
string
Indicates that the elements in array should be type double.
Boolean
string
Indicates that the elements in array should be type boolean.
String
string
Indicates that the elements in array should be type string.
dynamicAtlasManager
DynamicAtlasManager
Methods
speed
or less (speed < 1) time.
follow
Create a follow action which makes its target follows another node.
setPoints
Points setter
cardinalSplineTo
Creates an action with a Cardinal Spline array of points and tension.
updatePosition
update position of target
cardinalSplineBy
Creates an action with a Cardinal Spline array of points and tension.
catmullRomTo
Creates an action with a Cardinal Spline array of points and tension.
catmullRomBy
Creates an action with a Cardinal Spline array of points and tension.
easeIn
Creates the action easing object with the rate parameter.
easeOut
Creates the action easing object with the rate parameter.
easeInOut
Creates the action easing object with the rate parameter.
easeExponentialIn
Creates the action easing object with the rate parameter.
easeExponentialOut
Creates the action easing object.
easeExponentialInOut
Creates an EaseExponentialInOut action easing object.
easeSineIn
Creates an EaseSineIn action.
easeSineOut
Creates an EaseSineOut action easing object.
easeSineInOut
Creates the action easing object.
easeElasticIn
Creates the action easing object with the period in radians (default is 0.3).
easeElasticOut
Creates the action easing object with the period in radians (default is 0.3).
easeElasticInOut
Creates the action easing object with the period in radians (default is 0.3).
easeBounceIn
Creates the action easing object.
easeBounceOut
Creates the action easing object.
easeBounceInOut
Creates the action easing object.
easeBackIn
Creates the action easing object.
easeBackOut
Creates the action easing object.
easeBackInOut
Creates the action easing object.
easeBezierAction
Creates the action easing object.
easeQuadraticActionIn
Creates the action easing object.
easeQuadraticActionOut
Creates the action easing object.
easeQuadraticActionInOut
Creates the action easing object.
easeQuarticActionIn
Creates the action easing object.
easeQuarticActionOut
Creates the action easing object.
easeQuarticActionInOut
Creates the action easing object.
easeQuinticActionIn
Creates the action easing object.
easeQuinticActionOut
Creates the action easing object.
easeQuinticActionInOut
Creates the action easing object.
easeCircleActionIn
Creates the action easing object.
easeCircleActionOut
Creates the action easing object.
easeCircleActionInOut
Creates the action easing object.
easeCubicActionIn
Creates the action easing object.
easeCubicActionOut
Creates the action easing object.
easeCubicActionInOut
Creates the action easing object.
show
Show the Node.
hide
Hide the node.
toggleVisibility
Toggles the visibility of a node.
removeSelf
Create a RemoveSelf object with a flag indicate whether the target should be cleaned up while removing.
flipX
Create a FlipX action to flip or unflip the target.
flipY
Create a FlipY action to flip or unflip the target.
place
Creates a Place action with a position.
callFunc
Creates the action with the callback.
sequence
Helper constructor to create an array of sequenceable actions
repeat
Creates a Repeat action.
repeatForever
Create a acton which repeat forever, as it runs forever, it can't be added into cc.sequence and cc.spawn.
spawn
Create a spawn action which runs several actions in parallel.
rotateTo
Rotates a Node object to a certain angle by modifying its rotation property.
rotateBy
Rotates a Node object clockwise a number of degrees by modifying its rotation property.
moveBy
Moves a Node object x,y pixels by modifying its position property.
moveTo
Moves a Node object to the position x,y.
skewTo
Create a action which skews a Node object to given angles by modifying its skewX and skewY properties.
skewBy
Skews a Node object by skewX and skewY degrees.
jumpBy
Moves a Node object simulating a parabolic jump movement by modifying it's position property.
jumpTo
Moves a Node object to a parabolic position simulating a jump movement by modifying its position property.
bezierBy
An action that moves the target with a cubic Bezier curve by a certain distance.
bezierTo
An action that moves the target with a cubic Bezier curve to a destination point.
scaleTo
Scales a Node object to a zoom factor by modifying it's scale property.
scaleBy
Scales a Node object a zoom factor by modifying it's scale property.
blink
Blinks a Node object by modifying it's visible property.
fadeTo
Fades an object that implements the cc.RGBAProtocol protocol.
fadeIn
Fades In an object that implements the cc.RGBAProtocol protocol.
fadeOut
Fades Out an object that implements the cc.RGBAProtocol protocol.
tintTo
Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
tintBy
Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
delayTime
Delays the action a certain amount of seconds.
reverseTime
Executes an action in reverse order, from time=duration to time=0.
targetedAction
Create an action with the specified action and forced target.
error
Outputs an error message to the Cocos Creator Console (editor) or Web Console (runtime)....
warn
Outputs a warning message to the Cocos Creator Console (editor) or Web Console (runtime).
log
Outputs a message to the Cocos Creator Console (editor) or Web Console (runtime).
color
Alpha channel is optional.
rect
The convenience method to create a new Rect.
size
Helper function that creates a cc.Size....
v2
The convenience method to create a new cc.Vec2.
p
This function is deprecated since v2.0, please use V2.
find
Finds a node by hierarchy path, the path is case-sensitive.
Class
Defines a CCClass using the given specification, please see Class for details.
_isCCClass
Checks whether the constructor is created by cc.Class
Enum
Define an enum type.
getList
handleTouchesBegin
handleTouchesMove
handleTouchesEnd
handleTouchesCancel
getSetOfTouchesEndOrCancel
getHTMLElementPosition
getPreTouch
setPreTouch
getTouchByXY
getMouseEvent
getPointByEvent
getTouchesByEvent
registerSystemEvent
update
isValid
When an object's destroy
is called, it is actually destroyed after the end of this frame.
deserialize
Deserialize json to cc.Asset
instantiate
Clones the object original
and returns the clone, or instantiate a node from the Prefab.
Details
Properties
ENGINE_VERSION
The current version of Cocos2d being used.
Please DO NOT remove this String, it is an important flag for bug tracking.
If you post a bug to forum, please attach this flag.
director
Director
game
This is a Game instance.
systemEvent
The System event singleton for global usage
srcBlendFactor
specify the source Blend Factor, this will generate a custom material object, please pay attention to the memory cost.
Examples
sprite.srcBlendFactor = cc.macro.BlendFactor.ONE;
dstBlendFactor
specify the destination Blend Factor.
Examples
sprite.dstBlendFactor = cc.macro.BlendFactor.ONE;
view
cc.view is the shared view object.
winSize
cc.winSize is the alias object for the size of the current game window.
Integer
Specify that the input value must be integer in Inspector.
Also used to indicates that the elements in array should be type integer.
Examples
member: {
default: [],
type: cc.Integer
}
Float
Indicates that the elements in array should be type double.
Examples
member: {
default: [],
type: cc.Float
}
Boolean
Indicates that the elements in array should be type boolean.
Examples
member: {
default: [],
type: cc.Boolean
}
String
Indicates that the elements in array should be type string.
Examples
member: {
default: [],
type: cc.String
}
dynamicAtlasManager
Methods
speed
Creates the speed action which changes the speed of an action, making it take longer (speed > 1)
or less (speed < 1) time.
Useful to simulate 'slow motion' or 'fast forward' effect.
Parameters
Examples
var action = cc.scaleTo(0.2, 1, 0.6);
var newAction = cc.speed(action, 0.5);
follow
Create a follow action which makes its target follows another node.
Parameters
Examples
var followAction = cc.follow(targetNode, cc.rect(0, 0, screenWidth * 2 - 100, screenHeight));
node.runAction(followAction);
var followAction = cc.follow(targetNode);
node.runAction(followAction);
setPoints
Points setter
Parameters
cardinalSplineTo
Creates an action with a Cardinal Spline array of points and tension.
Parameters
Examples
var action1 = cc.cardinalSplineTo(3, array, 0);
updatePosition
update position of target
Parameters
cardinalSplineBy
Creates an action with a Cardinal Spline array of points and tension.
Parameters
catmullRomTo
Creates an action with a Cardinal Spline array of points and tension.
Parameters
Examples
var action1 = cc.catmullRomTo(3, array);
catmullRomBy
Creates an action with a Cardinal Spline array of points and tension.
Parameters
Examples
var action1 = cc.catmullRomBy(3, array);
easeIn
Creates the action easing object with the rate parameter.
From slow to fast.
Parameters
Examples
action.easing(cc.easeIn(3.0));
easeOut
Creates the action easing object with the rate parameter.
From fast to slow.
Parameters
Examples
action.easing(cc.easeOut(3.0));
easeInOut
Creates the action easing object with the rate parameter.
Slow to fast then to slow.
Parameters
Examples
action.easing(cc.easeInOut(3.0));
easeExponentialIn
Creates the action easing object with the rate parameter.
Reference easeInExpo:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeExponentialIn());
easeExponentialOut
Creates the action easing object.
Reference easeOutExpo:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeExponentialOut());
easeExponentialInOut
Creates an EaseExponentialInOut action easing object.
Reference easeInOutExpo:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeExponentialInOut());
easeSineIn
Creates an EaseSineIn action.
Reference easeInSine:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeSineIn());
easeSineOut
Creates an EaseSineOut action easing object.
Reference easeOutSine:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeSineOut());
easeSineInOut
Creates the action easing object.
Reference easeInOutSine:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeSineInOut());
easeElasticIn
Creates the action easing object with the period in radians (default is 0.3).
Reference easeInElastic:
http://www.zhihu.com/question/21981571/answer/19925418
Parameters
Examples
action.easing(cc.easeElasticIn(3.0));
easeElasticOut
Creates the action easing object with the period in radians (default is 0.3).
Reference easeOutElastic:
http://www.zhihu.com/question/21981571/answer/19925418
Parameters
Examples
action.easing(cc.easeElasticOut(3.0));
easeElasticInOut
Creates the action easing object with the period in radians (default is 0.3).
Reference easeInOutElastic:
http://www.zhihu.com/question/21981571/answer/19925418
Parameters
Examples
action.easing(cc.easeElasticInOut(3.0));
easeBounceIn
Creates the action easing object.
Eased bounce effect at the beginning.
Examples
action.easing(cc.easeBounceIn());
easeBounceOut
Creates the action easing object.
Eased bounce effect at the ending.
Examples
action.easing(cc.easeBounceOut());
easeBounceInOut
Creates the action easing object.
Eased bounce effect at the begining and ending.
Examples
action.easing(cc.easeBounceInOut());
easeBackIn
Creates the action easing object.
In the opposite direction to move slowly, and then accelerated to the right direction.
Examples
action.easing(cc.easeBackIn());
easeBackOut
Creates the action easing object.
Fast moving more than the finish, and then slowly back to the finish.
Examples
action.easing(cc.easeBackOut());
easeBackInOut
Creates the action easing object.
Begining of cc.EaseBackIn. Ending of cc.EaseBackOut.
Examples
action.easing(cc.easeBackInOut());
easeBezierAction
Creates the action easing object.
Into the 4 reference point.
To calculate the motion curve.
Parameters
p0
Number The first bezier parameter
p1
Number The second bezier parameter
p2
Number The third bezier parameter
p3
Number The fourth bezier parameter
Examples
action.easing(cc.easeBezierAction(0.5, 0.5, 1.0, 1.0));
easeQuadraticActionIn
Creates the action easing object.
Reference easeInQuad:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeQuadraticActionIn());
easeQuadraticActionOut
Creates the action easing object.
Reference easeOutQuad:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeQuadraticActionOut());
easeQuadraticActionInOut
Creates the action easing object.
Reference easeInOutQuad:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeQuadraticActionInOut());
easeQuarticActionIn
Creates the action easing object.
Reference easeIntQuart:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeQuarticActionIn());
easeQuarticActionOut
Creates the action easing object.
Reference easeOutQuart:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.QuarticActionOut());
easeQuarticActionInOut
Creates the action easing object.
Reference easeInOutQuart:
http://www.zhihu.com/question/21981571/answer/19925418
easeQuinticActionIn
Creates the action easing object.
Reference easeInQuint:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeQuinticActionIn());
easeQuinticActionOut
Creates the action easing object.
Reference easeOutQuint:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeQuadraticActionOut());
easeQuinticActionInOut
Creates the action easing object.
Reference easeInOutQuint:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeQuinticActionInOut());
easeCircleActionIn
Creates the action easing object.
Reference easeInCirc:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeCircleActionIn());
easeCircleActionOut
Creates the action easing object.
Reference easeOutCirc:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
actioneasing(cc.easeCircleActionOut());
easeCircleActionInOut
Creates the action easing object.
Reference easeInOutCirc:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeCircleActionInOut());
easeCubicActionIn
Creates the action easing object.
Reference easeInCubic:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeCubicActionIn());
easeCubicActionOut
Creates the action easing object.
Reference easeOutCubic:
http://www.zhihu.com/question/21981571/answer/19925418
Examples
action.easing(cc.easeCubicActionOut());
easeCubicActionInOut
Creates the action easing object.
Reference easeInOutCubic:
http://www.zhihu.com/question/21981571/answer/19925418
show
Show the Node.
Examples
var showAction = cc.show();
hide
Hide the node.
Examples
var hideAction = cc.hide();
toggleVisibility
Toggles the visibility of a node.
Examples
var toggleVisibilityAction = cc.toggleVisibility();
removeSelf
Create a RemoveSelf object with a flag indicate whether the target should be cleaned up while removing.
Parameters
Examples
var removeSelfAction = cc.removeSelf();
flipX
Create a FlipX action to flip or unflip the target.
Parameters
flip
Boolean Indicate whether the target should be flipped or not
Examples
var flipXAction = cc.flipX(true);
flipY
Create a FlipY action to flip or unflip the target.
Parameters
Examples
var flipYAction = cc.flipY(true);
place
Creates a Place action with a position.
Parameters
Examples
var placeAction = cc.place(cc.v2(200, 200));
var placeAction = cc.place(200, 200);
callFunc
Creates the action with the callback.
Parameters
selector
function
selectorTarget
object
data
Any data for function, it accepts all data types.
Examples
var finish = cc.callFunc(this.removeSprite, this);
var finish = cc.callFunc(this.removeFromParentAndCleanup, this._grossini, true);
sequence
Helper constructor to create an array of sequenceable actions
The created action will run actions sequentially, one after another.
Parameters
Examples
var seq = cc.sequence(act1, act2);
var seq = cc.sequence(actArray);
repeat
Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30)
Parameters
Examples
var rep = cc.repeat(cc.sequence(jump2, jump1), 5);
repeatForever
Create a acton which repeat forever, as it runs forever, it can't be added into cc.sequence and cc.spawn.
Parameters
Examples
var repeat = cc.repeatForever(cc.rotateBy(1.0, 360));
spawn
Create a spawn action which runs several actions in parallel.
Parameters
Examples
var action = cc.spawn(cc.jumpBy(2, cc.v2(300, 0), 50, 4), cc.rotateBy(2, 720));
todo:It should be the direct use new
rotateTo
Rotates a Node object to a certain angle by modifying its rotation property.
The direction will be decided by the shortest angle.
Parameters
duration
Number duration in seconds
deltaAngleX
Number deltaAngleX in degrees.
deltaAngleY
Number deltaAngleY in degrees.
Examples
var rotateTo = cc.rotateTo(2, 61.0);
rotateBy
Rotates a Node object clockwise a number of degrees by modifying its rotation property.
Relative to its properties to modify.
Parameters
duration
Number duration in seconds
deltaAngleX
Number deltaAngleX in degrees
deltaAngleY
Number deltaAngleY in degrees
Examples
var actionBy = cc.rotateBy(2, 360);
moveBy
Moves a Node object x,y pixels by modifying its position property.
x and y are relative to the position of the object.
Several MoveBy actions can be concurrently called, and the resulting
movement will be the sum of individual movements.
Parameters
Examples
var actionTo = cc.moveBy(2, cc.v2(windowSize.width - 40, windowSize.height - 40));
moveTo
Moves a Node object to the position x,y. x and y are absolute coordinates by modifying its position property.
Several MoveTo actions can be concurrently called, and the resulting
movement will be the sum of individual movements.
Parameters
Examples
var actionBy = cc.moveTo(2, cc.v2(80, 80));
skewTo
Create a action which skews a Node object to given angles by modifying its skewX and skewY properties.
Changes to the specified value.
Parameters
Examples
var actionTo = cc.skewTo(2, 37.2, -37.2);
skewBy
Skews a Node object by skewX and skewY degrees.
Relative to its property modification.
Parameters
t
Number time in seconds
sx
Number sx skew in degrees for X axis
sy
Number sy skew in degrees for Y axis
Examples
var actionBy = cc.skewBy(2, 0, -90);
jumpBy
Moves a Node object simulating a parabolic jump movement by modifying it's position property.
Relative to its movement.
Parameters
Examples
var actionBy = cc.jumpBy(2, cc.v2(300, 0), 50, 4);
var actionBy = cc.jumpBy(2, 300, 0, 50, 4);
jumpTo
Moves a Node object to a parabolic position simulating a jump movement by modifying its position property.
Jump to the specified location.
Parameters
Examples
var actionTo = cc.jumpTo(2, cc.v2(300, 300), 50, 4);
var actionTo = cc.jumpTo(2, 300, 300, 50, 4);
bezierBy
An action that moves the target with a cubic Bezier curve by a certain distance.
Relative to its movement.
Parameters
Examples
var bezier = [cc.v2(0, windowSize.height / 2), cc.v2(300, -windowSize.height / 2), cc.v2(300, 100)];
var bezierForward = cc.bezierBy(3, bezier);
bezierTo
An action that moves the target with a cubic Bezier curve to a destination point.
Parameters
Examples
var bezier = [cc.v2(0, windowSize.height / 2), cc.v2(300, -windowSize.height / 2), cc.v2(300, 100)];
var bezierTo = cc.bezierTo(2, bezier);
scaleTo
Scales a Node object to a zoom factor by modifying it's scale property.
Parameters
duration
Number
sx
Number scale parameter in X
sy
Number scale parameter in Y, if Null equal to sx
Examples
var actionTo = cc.scaleTo(2, 0.5);
var actionTo = cc.scaleTo(2, 0.5, 2);
scaleBy
Scales a Node object a zoom factor by modifying it's scale property.
Relative to its changes.
Parameters
duration
Number duration in seconds
sx
Number sx scale parameter in X
sy
Number | Null sy scale parameter in Y, if Null equal to sx
Examples
var actionBy = cc.scaleBy(2, 2);
var actionBy2 = cc.scaleBy(2, 0.25, 4.5);
blink
Blinks a Node object by modifying it's visible property.
Parameters
duration
Number duration in seconds
blinks
Number blinks in times
Examples
var action = cc.blink(2, 10);
fadeTo
Fades an object that implements the cc.RGBAProtocol protocol.
It modifies the opacity from the current value to a custom one.
Parameters
Examples
var action = cc.fadeTo(1.0, 0);
fadeIn
Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255.
Parameters
duration
Number duration in seconds
Examples
var action = cc.fadeIn(1.0);
fadeOut
Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0.
Parameters
Examples
var action = cc.fadeOut(1.0);
tintTo
Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
Parameters
Examples
var action = cc.tintTo(2, 255, 0, 255);
tintBy
Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
Relative to their own color change.
Parameters
Examples
var action = cc.tintBy(2, -127, -255, -127);
delayTime
Delays the action a certain amount of seconds.
Parameters
Examples
var delay = cc.delayTime(1);
reverseTime
Executes an action in reverse order, from time=duration to time=0.
Parameters
Examples
var reverse = cc.reverseTime(this);
targetedAction
Create an action with the specified action and forced target.
Parameters
error
Outputs an error message to the Cocos Creator Console (editor) or Web Console (runtime).
- In Cocos Creator, error is red.
- In Chrome, error have a red icon along with red message text.
Parameters
msg
Any A JavaScript string containing zero or more substitution strings.
subst
Any JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
warn
Outputs a warning message to the Cocos Creator Console (editor) or Web Console (runtime).
- In Cocos Creator, warning is yellow.
- In Chrome, warning have a yellow warning icon with the message text.
Parameters
msg
Any A JavaScript string containing zero or more substitution strings.
subst
Any JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
log
Outputs a message to the Cocos Creator Console (editor) or Web Console (runtime).
Parameters
msg
String | Any A JavaScript string containing zero or more substitution strings.
subst
Any JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
color
The convenience method to create a new Color/Color:method
Alpha channel is optional. Default value is 255.
Parameters
Examples
```Not found for the example path: temp-src/engine/docs/utils/api/engine/docs/cocos2d/core/value-types/CCColor/color.js
rect
The convenience method to create a new Rect.
see Rect/Rect:method
Parameters
Examples
var a = new cc.Rect(0 , 0, 10, 0);
size
Helper function that creates a cc.Size.
Please use cc.p or cc.v2 instead, it will soon replace cc.Size.
Parameters
Examples
```Not found for the example path: temp-src/engine/docs/utils/api/engine/docs/cocos2d/core/value-types/CCSize/size.js
v2
The convenience method to create a new cc.Vec2.
Parameters
Examples
var v1 = cc.v2();
var v2 = cc.v2(0, 0);
var v3 = cc.v2(v2);
var v4 = cc.v2({x: 100, y: 100});
p
This function is deprecated since v2.0, please use V2.
Parameters
find
Finds a node by hierarchy path, the path is case-sensitive.
It will traverse the hierarchy by splitting the path using '/' character.
This function will still returns the node even if it is inactive.
It is recommended to not use this function every frame instead cache the result at startup.
Parameters
Class
Defines a CCClass using the given specification, please see Class for details.
Parameters
options
Object
name
String The class name used for serialization.
extends
Function The base class.
ctor
Function The constructor.
__ctor__
Function The same as ctor, but less encapsulated.
properties
Object The property definitions.
statics
Object The static members.
mixins
Function[]
editor
Object attributes for Component listed below.
executeInEditMode
Boolean Allows the current component to run in edit mode. By default, all components are executed only at runtime, meaning that they will not have their callback functions executed while the Editor is in edit mode.
requireComponent
Function Automatically add required component as a dependency.
menu
String The menu path to register a component to the editors "Component" menu. Eg. "Rendering/Camera".
executionOrder
Number The execution order of lifecycle methods for Component. Those less than 0 will execute before while those greater than 0 will execute after. The order will only affect onLoad, onEnable, start, update and lateUpdate while onDisable and onDestroy will not be affected.
disallowMultiple
Boolean If specified to a type, prevents Component of the same type (or subtype) to be added more than once to a Node.
playOnFocus
Boolean This property is only available when executeInEditMode is set. If specified, the editor's scene view will keep updating this node in 60 fps when it is selected, otherwise, it will update only if necessary.
inspector
String Customize the page url used by the current component to render in the Properties.
icon
String Customize the icon that the current component displays in the editor.
help
String The custom documentation URL
update
Function lifecycle method for Component, see update
lateUpdate
Function lifecycle method for Component, see lateUpdate
onLoad
Function lifecycle method for Component, see onLoad
start
Function lifecycle method for Component, see start
onEnable
Function lifecycle method for Component, see onEnable
onDisable
Function lifecycle method for Component, see onDisable
onDestroy
Function lifecycle method for Component, see onDestroy
onFocusInEditor
Function lifecycle method for Component, see onFocusInEditor
onLostFocusInEditor
Function lifecycle method for Component, see onLostFocusInEditor
resetInEditor
Function lifecycle method for Component, see resetInEditor
onRestore
Function for Component only, see onRestore
_getLocalBounds
Function for Component only, see _getLocalBounds
Examples
var Node = cc.Class();
var Sprite = cc.Class({
name: 'Sprite',
extends: Node,
ctor: function () {
this.url = "";
this.id = 0;
},
statics: {
count: 0,
getBounds: function (spriteList) {
}
},
properties {
width: {
default: 128,
type: 'Integer',
tooltip: 'The width of sprite'
},
height: 128,
size: {
get: function () {
return cc.v2(this.width, this.height);
}
}
},
load: function () {
};
});
var obj = new Sprite();
obj.url = 'sprite.png';
obj.load();
_isCCClass
Checks whether the constructor is created by cc.Class
Parameters
Enum
Define an enum type.
If a enum item has a value of -1, it will be given an Integer number according to it's order in the list.
Otherwise it will use the value specified by user who writes the enum definition.
Parameters
obj
object a JavaScript literal object containing enum names and values, or a TypeScript enum type
Examples
var WrapMode = cc.Enum({
Repeat: -1,
Clamp: -1
});
var FlagType = cc.Enum({
Flag1: 1,
Flag2: 2,
Flag3: 4,
Flag4: 8,
});
var AtlasSizeList = cc.Enum({
128: 128,
256: 256,
512: 512,
1024: 1024,
});
enum Direction {
Up,
Down,
Left,
Right
}
const {ccclass, property} = cc._decorator;
@ccclass
class NewScript extends cc.Component {
@property({
type: cc.Enum(Direction)
})
direction: Direction = Direction.Up;
}
getList
Parameters
enumDef
Object the enum type defined from cc.Enum
handleTouchesBegin
Parameters
handleTouchesMove
Parameters
handleTouchesEnd
Parameters
handleTouchesCancel
Parameters
getSetOfTouchesEndOrCancel
Parameters
getHTMLElementPosition
Parameters
getPreTouch
Parameters
setPreTouch
Parameters
getTouchByXY
Parameters
getMouseEvent
Parameters
getPointByEvent
Parameters
getTouchesByEvent
Parameters
registerSystemEvent
Parameters
update
Parameters
isValid
Checks whether the object is non-nil and not yet 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.
Parameters
value
Any
strictMode
Boolean If true, Object called destroy() in this frame will also treated as invalid.
Examples
var node = new cc.Node();
cc.log(cc.isValid(node));
node.destroy();
cc.log(cc.isValid(node));
cc.log(cc.isValid(node));
deserialize
Deserialize json to cc.Asset
Parameters
data
String | Object the serialized cc.Asset json string or json object.
details
Details additional loading result
options
Object
instantiate
Clones the object original
and returns the clone, or instantiate a node from the Prefab.
Parameters
original
Prefab | Node | Object An existing object that you want to make a copy of.
Examples
var scene = cc.director.getScene();
var node = cc.instantiate(prefabAsset);
node.parent = scene;
var scene = cc.director.getScene();
var node = cc.instantiate(targetNode);
node.parent = scene;