Cocos Creator API

1.2.0

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

Module cc

The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace.

Class

Properties

view View

cc.view is the shared view object.

director Director

Director

winSize Size

cc.winSize is the alias object for the size of the current game window.

game Game

Integer string readOnly

Specify that the input value must be integer in Inspector. Also used to indicates that the elements in array should be type integer.

Float string readOnly

Indicates that the elements in array should be type double.

Boolean string readOnly

Indicates that the elements in array should be type boolean.

String string readOnly

Indicates that the elements in array should be type string.

Methods

_initDebugSetting
(
  • mode
)

Init Debug setting.

name type description
mode DebugMode

error
(
  • obj
  • subst
)

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.
name type description
obj 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
(
  • obj
  • subst
)

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.
name type description
obj 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
(
  • obj
  • subst
)

Outputs a message to the Cocos Creator Console (editor) or Web Console (runtime).

name type description
obj 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.

info
(
  • obj
  • subst
)

Outputs an informational message to the Cocos Creator Console (editor) or Web Console (runtime).

  • In Cocos Creator, info is blue.
  • In Firefox and Chrome, a small "i" icon is displayed next to these items in the Web Console's log.
name type description
obj 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.

speed
(
  • action
  • speed
)
Action

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.

name type description
action ActionInterval
speed Number

returns:

type: Action

examples:

// change the target action speed;
var action = cc.scaleTo(0.2, 1, 0.6);
var newAction = cc.speed(action, 0.5);

follow
(
  • followedNode
  • rect
)
Action | Null

Create a follow action which makes its target follows another node.

name type description
followedNode Node
rect Rect

returns:

type: Action | Null

returns the cc.Follow object on success

examples:

// example
// creates the action with a set boundary
var followAction = cc.follow(targetNode, cc.rect(0, 0, screenWidth * 2 - 100, screenHeight));
node.runAction(followAction);

// creates the action with no boundary set
var followAction = cc.follow(targetNode);
node.runAction(followAction);

setPoints
(
  • points
)

Points setter

name type description
points Array

cardinalSplineTo
(
  • duration
  • points
  • tension
)
ActionInterval

Creates an action with a Cardinal Spline array of points and tension.

name type description
duration Number
points Array

array of control points

tension Number

returns:

examples:

//create a cc.CardinalSplineTo
var action1 = cc.cardinalSplineTo(3, array, 0);

updatePosition
(
  • newPos
)

update position of target

name type description
newPos Vec2

cardinalSplineBy
(
  • duration
  • points
  • tension
)
ActionInterval

Creates an action with a Cardinal Spline array of points and tension.

name type description
duration Number
points Array
tension Number

returns:

catmullRomTo
(
  • dt
  • points
)
ActionInterval

Creates an action with a Cardinal Spline array of points and tension.

name type description
dt Number
points Array

returns:

examples:

var action1 = cc.catmullRomTo(3, array);

catmullRomBy
(
  • dt
  • points
)
ActionInterval

Creates an action with a Cardinal Spline array of points and tension.

name type description
dt Number
points Array

returns:

examples:

var action1 = cc.catmullRomBy(3, array);

easeIn
(
  • rate
)
Object

Creates the action easing object with the rate parameter.
From slow to fast.

name type description
rate Number

returns:

type: Object

examples:

// example
action.easing(cc.easeIn(3.0));

easeOut
(
  • rate
)
Object

Creates the action easing object with the rate parameter.
From fast to slow.

name type description
rate Number

returns:

type: Object

examples:

// example
action.easing(cc.easeOut(3.0));

easeInOut
(
  • rate
)
Object

Creates the action easing object with the rate parameter.
Slow to fast then to slow.

name type description
rate Number

returns:

type: Object

examples:

//The new usage
action.easing(cc.easeInOut(3.0));

easeExponentialIn ( ) Object

Creates the action easing object with the rate parameter.
Reference easeInExpo:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

// example
action.easing(cc.easeExponentialIn());

easeExponentialOut ( ) Object

Creates the action easing object.
Reference easeOutExpo:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

// example
action.easing(cc.easeExponentialOut());

easeExponentialInOut ( ) Object

Creates an EaseExponentialInOut action easing object.
Reference easeInOutExpo:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

// example
action.easing(cc.easeExponentialInOut());

easeSineIn ( ) Object

Creates an EaseSineIn action.
Reference easeInSine:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

// example
action.easing(cc.easeSineIn());

easeSineOut ( ) Object

Creates an EaseSineOut action easing object.
Reference easeOutSine:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

// example
action.easing(cc.easeSineOut());

easeSineInOut ( ) Object

Creates the action easing object.
Reference easeInOutSine:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

// example
action.easing(cc.easeSineInOut());

easeElasticIn
(
  • period
)
Object

Creates the action easing obejct with the period in radians (default is 0.3).
Reference easeInElastic:
http://www.zhihu.com/question/21981571/answer/19925418

name type description
period Number

returns:

type: Object

examples:

// example
action.easing(cc.easeElasticIn(3.0));

easeElasticOut
(
  • period
)
Object

Creates the action easing object with the period in radians (default is 0.3).
Reference easeOutElastic:
http://www.zhihu.com/question/21981571/answer/19925418

name type description
period Number

returns:

type: Object

examples:

// example
action.easing(cc.easeElasticOut(3.0));

easeElasticInOut
(
  • period
)
Object

Creates the action easing object with the period in radians (default is 0.3).
Reference easeInOutElastic:
http://www.zhihu.com/question/21981571/answer/19925418

name type description
period Number

returns:

type: Object

examples:

// example
action.easing(cc.easeElasticInOut(3.0));

easeBounceIn ( ) Object

Creates the action easing object.
Eased bounce effect at the beginning.

returns:

type: Object

examples:

// example
action.easing(cc.easeBounceIn());

easeBounceOut ( ) Object

Creates the action easing object.
Eased bounce effect at the ending.

returns:

type: Object

examples:

// example
action.easing(cc.easeBounceOut());

easeBounceInOut ( ) Object

Creates the action easing object.
Eased bounce effect at the begining and ending.

returns:

type: Object

examples:

// example
action.easing(cc.easeBounceInOut());

easeBackIn ( ) Object

Creates the action easing object.
In the opposite direction to move slowly, and then accelerated to the right direction.

returns:

type: Object

examples:

// example
action.easing(cc.easeBackIn());

easeBackOut ( ) Object

Creates the action easing object.
Fast moving more than the finish, and then slowly back to the finish.

returns:

type: Object

examples:

// example
action.easing(cc.easeBackOut());

easeBackInOut ( ) Object

Creates the action easing object.
Begining of cc.EaseBackIn. Ending of cc.EaseBackOut.

returns:

type: Object

examples:

// example
action.easing(cc.easeBackInOut());

easeBezierAction
(
  • p0
  • p1
  • p2
  • p3
)
Object

Creates the action easing object.
Into the 4 reference point.
To calculate the motion curve.

name type description
p0 Number

The first bezier parameter

p1 Number

The second bezier parameter

p2 Number

The third bezier parameter

p3 Number

The fourth bezier parameter

returns:

type: Object

examples:

// example
action.easing(cc.easeBezierAction(0.5, 0.5, 1.0, 1.0));

easeQuadraticActionIn ( ) Object

Creates the action easing object.
Reference easeInQuad:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeQuadraticActionIn());

easeQuadraticActionOut ( ) Object

Creates the action easing object.
Reference easeOutQuad:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeQuadraticActionOut());

easeQuadraticActionInOut ( ) Object

Creates the action easing object.
Reference easeInOutQuad:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeQuadraticActionInOut());

easeQuarticActionIn ( ) Object

Creates the action easing object.
Reference easeIntQuart:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeQuarticActionIn());

easeQuarticActionOut ( ) Object

Creates the action easing object.
Reference easeOutQuart:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.QuarticActionOut());

easeQuarticActionInOut ( ) Object

Creates the action easing object.
Reference easeInOutQuart:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

easeQuinticActionIn ( ) Object

Creates the action easing object.
Reference easeInQuint:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeQuinticActionIn());

easeQuinticActionOut ( ) Object

Creates the action easing object.
Reference easeOutQuint:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeQuadraticActionOut());

easeQuinticActionInOut ( ) Object

Creates the action easing object.
Reference easeInOutQuint:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeQuinticActionInOut());

easeCircleActionIn ( ) Object

Creates the action easing object.
Reference easeInCirc:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeCircleActionIn());

easeCircleActionOut ( ) Object

Creates the action easing object.
Reference easeOutCirc:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

easeCircleActionInOut ( ) Object

Creates the action easing object.
Reference easeInOutCirc:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeCircleActionInOut());

easeCubicActionIn ( ) Object

Creates the action easing object.
Reference easeInCubic:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeCubicActionIn());

easeCubicActionOut ( ) Object

Creates the action easing object.
Reference easeOutCubic:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

examples:

//example
action.easing(cc.easeCubicActionOut());

easeCubicActionInOut ( ) Object

Creates the action easing object.
Reference easeInOutCubic:
http://www.zhihu.com/question/21981571/answer/19925418

returns:

type: Object

show ( ) ActionInstant

Show the Node.

returns:

examples:

// example
var showAction = cc.show();

hide ( ) ActionInstant

Hide the node.

returns:

examples:

// example
var hideAction = cc.hide();

toggleVisibility ( ) ActionInstant

Toggles the visibility of a node.

returns:

examples:

// example
var toggleVisibilityAction = cc.toggleVisibility();

removeSelf
(
  • isNeedCleanUp
)
ActionInstant

Create a RemoveSelf object with a flag indicate whether the target should be cleaned up while removing.

name type description
isNeedCleanUp Boolean

returns:

examples:

// example
var removeSelfAction = cc.removeSelf();

flipX
(
  • flip
)
ActionInstant

Create a FlipX action to flip or unflip the target.

name type description
flip Boolean

Indicate whether the target should be flipped or not

returns:

examples:

var flipXAction = cc.flipX(true);

flipY
(
  • flip
)
ActionInstant

Create a FlipY action to flip or unflip the target.

name type description
flip Boolean

returns:

examples:

var flipYAction = cc.flipY(true);

place
(
  • pos
  • [y ]
)
ActionInstant

Creates a Place action with a position.

name type description
pos Vec2 | Number
y optional Number

returns:

examples:

// example
var placeAction = cc.place(cc.p(200, 200));
var placeAction = cc.place(200, 200);

callFunc
(
  • selector
  • [selectorTarget ]
  • [data ]
)
ActionInstant

Creates the action with the callback.