Cocos Creator API

0.7.1

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

Properties

PRIORITY_NON_SYSTEM Number readOnly

Minimum priority level for user scheduling.

FMT_JPG Number readOnly

Image Format:JPG

FMT_PNG Number readOnly

Image Format:PNG

FMT_TIFF Number readOnly

Image Format:TIFF

FMT_RAWDATA Number readOnly

Image Format:RAWDATA

FMT_WEBP Number readOnly

Image Format:WEBP

FMT_UNKNOWN Number readOnly

Image Format:UNKNOWN

FIX_ARTIFACTS_BY_STRECHING_TEXEL Number readOnly

If enabled, the texture coordinates will be calculated by using this formula:
- texCoord.left = (rect.x2+1) / (texture.wide2);
- texCoord.right = texCoord.left + (rect.width2-2)/(texture.wide2);

The same for bottom and top.

This formula prevents artifacts by using 99% of the texture.
The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool.

Affected nodes:
- _ccsg.Sprite / cc.SpriteBatchNode and subclasses: cc.LabelBMFont, cc.TMXTiledMap
- cc.LabelAtlas
- cc.QuadParticleSystem
- cc.TileMap

To enabled set it to 1. Disabled by default.
To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h

DIRECTOR_STATS_POSITION Vec2 readOnly

Position of the FPS (Default: 0,0 (bottom-left corner))
To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h

DIRECTOR_FPS_INTERVAL Number readOnly

Seconds between FPS updates.
0.5 seconds, means that the FPS number will be updated every 0.5 seconds.
Having a bigger number means a more reliable FPS

Default value: 0.1f
To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h

COCOSNODE_RENDER_SUBPIXEL Number readOnly

If enabled, the ccsg.Node objects (_ccsg.Sprite, _ccsg.Label,etc) will be able to render in subpixels.
If disabled, integer pixels will be used.

To enable set it to 1. Enabled by default.
To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h

SPRITEBATCHNODE_RENDER_SUBPIXEL Number readOnly

If enabled, the _ccsg.Sprite objects rendered with cc.SpriteBatchNode will be able to render in subpixels.
If disabled, integer pixels will be used.

To enable set it to 1. Enabled by default.
To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h

AUTO_PREMULTIPLIED_ALPHA_FOR_PNG Number readOnly

Automatically premultiply alpha for PNG resources

OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA Number readOnly

If most of your images have pre-multiplied alpha, set it to 1 (if you are going to use .PNG/.JPG file images).
Only set to 0 if ALL your images by-pass Apple UIImage loading system (eg: if you use libpng or PVR images)

To enable set it to a value different than 0. Enabled by default.
To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h

TEXTURE_ATLAS_USE_TRIANGLE_STRIP Number readOnly

Use GL_TRIANGLE_STRIP instead of GL_TRIANGLES when rendering the texture atlas.
It seems it is the recommend way, but it is much slower, so, enable it at your own risk

To enable set it to a value different than 0. Disabled by default.
To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h

TEXTURE_ATLAS_USE_VAO Number readOnly

By default, cc.TextureAtlas (used by many cocos2d classes) will use VAO (Vertex Array Objects).
Apple recommends its usage but they might consume a lot of memory, specially if you use many of them.
So for certain cases, where you might need hundreds of VAO objects, it might be a good idea to disable it.

To disable it set it to 0. disable by default.(Not Supported on WebGL)
To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h

RETINA_DISPLAY_FILENAME_SUFFIX String readOnly

It's the suffix that will be appended to the files in order to load "retina display" images.

On an iPhone4 with Retina Display support enabled, the file @"sprite-hd.png" will be loaded instead of @"sprite.png".
If the file doesn't exist it will use the non-retina display image.

Platforms: Only used on Retina Display devices like iPhone 4.

USE_LA88_LABELS Number readOnly

If enabled, it will use LA88 (Luminance Alpha 16-bit textures) for CCLabelTTF objects.
If it is disabled, it will use A8 (Alpha 8-bit textures).
LA88 textures are 6% faster than A8 textures, but they will consume 2x memory.

This feature is enabled by default.

SPRITE_DEBUG_DRAW Number readOnly

If enabled, all subclasses of _ccsg.Sprite will draw a bounding box
Useful for debugging purposes only. It is recommend to leave it disabled.

To enable set it to a value different than 0. Disabled by default:
0 -- disabled
1 -- draw bounding box
2 -- draw texture box

SPRITEBATCHNODE_DEBUG_DRAW Number readOnly

If enabled, all subclasses of _ccsg.Sprite that are rendered using an cc.SpriteBatchNode draw a bounding box.
Useful for debugging purposes only. It is recommend to leave it disabled.

To enable set it to a value different than 0. Disabled by default.

LABELBMFONT_DEBUG_DRAW Number readOnly

If enabled, all subclasses of cc.LabelBMFont will draw a bounding box
Useful for debugging purposes only. It is recommend to leave it disabled.

To enable set it to a value different than 0. Disabled by default.

LABELATLAS_DEBUG_DRAW Number readOnly

If enabled, all subclasses of cc.LabelAtlas will draw a bounding box
Useful for debugging purposes only. It is recommend to leave it disabled.

To enable set it to a value different than 0. Disabled by default.

IS_RETINA_DISPLAY_SUPPORTED Number readOnly

Whether or not support retina display

DEFAULT_ENGINE String readOnly

Default engine

ENABLE_STACKABLE_ACTIONS Number readOnly

If enabled, actions that alter the position property (eg: CCMoveBy, CCJumpBy, CCBezierBy, etc..) will be stacked.
If you run 2 or more 'position' actions at the same time on a node, then end position will be the sum of all the positions.
If disabled, only the last run action will take effect.

ENABLE_GL_STATE_CACHE Number readOnly

If enabled, cocos2d will maintain an OpenGL state cache internally to avoid unnecessary switches.
In order to use them, you have to use the following functions, instead of the the GL ones:
- ccGLUseProgram() instead of glUseProgram()
- ccGLDeleteProgram() instead of glDeleteProgram()
- ccGLBlendFunc() instead of glBlendFunc()

If this functionality is disabled, then ccGLUseProgram(), ccGLDeleteProgram(), ccGLBlendFunc() will call the GL ones, without using the cache.
It is recommend to enable whenever possible to improve speed.
If you are migrating your code from GL ES 1.1, then keep it disabled. Once all your code works as expected, turn it on.

INVALID_INDEX Number readOnly

PI Number readOnly

PI is the ratio of a circle's circumference to its diameter.

FLT_MAX Number readOnly

FLT_MIN Number readOnly

RAD Number readOnly

DEG Number readOnly

UINT_MAX Number readOnly

maximum unsigned int value

REPEAT_FOREVER Number readOnly

FLT_EPSILON Number readOnly

ONE Number readOnly

ZERO Number readOnly

SRC_ALPHA Number readOnly

SRC_ALPHA_SATURATE Number readOnly

SRC_COLOR Number readOnly

DST_ALPHA Number readOnly

DST_COLOR Number readOnly

ONE_MINUS_SRC_ALPHA Number readOnly

ONE_MINUS_SRC_COLOR Number readOnly

ONE_MINUS_DST_ALPHA Number readOnly

ONE_MINUS_DST_COLOR Number readOnly

ONE_MINUS_CONSTANT_ALPHA Number readOnly

ONE_MINUS_CONSTANT_COLOR Number readOnly

LINEAR Number readOnly

the constant variable equals gl.LINEAR for texture

BLEND_SRC Number readOnly

default gl blend src function. Compatible with premultiplied alpha images.

BLEND_DST Number readOnly

default gl blend dst function. Compatible with premultiplied alpha images.

DEVICE_ORIENTATION_PORTRAIT Number readOnly

Device oriented vertically, home button on the bottom (UIDeviceOrientationPortrait)

DEVICE_ORIENTATION_LANDSCAPE_LEFT Number readOnly

Device oriented horizontally, home button on the right (UIDeviceOrientationLandscapeLeft)

DEVICE_ORIENTATION_PORTRAIT_UPSIDE_DOWN Number readOnly

Device oriented vertically, home button on the top (UIDeviceOrientationPortraitUpsideDown)

DEVICE_ORIENTATION_LANDSCAPE_RIGHT Number readOnly

Device oriented horizontally, home button on the left (UIDeviceOrientationLandscapeRight)

DEVICE_MAX_ORIENTATIONS Number readOnly

In browsers, we only support 2 orientations by change window size.

VERTEX_ATTRIB_FLAG_NONE Number readOnly

VERTEX_ATTRIB_FLAG_POSITION Number readOnly

VERTEX_ATTRIB_FLAG_COLOR Number readOnly

VERTEX_ATTRIB_FLAG_TEX_COORDS Number readOnly

VERTEX_ATTRIB_FLAG_POS_COLOR_TEX Number readOnly

GL_ALL Number readOnly

GL server side states

VERTEX_ATTRIB_POSITION Number readOnly

VERTEX_ATTRIB_COLOR Number readOnly

VERTEX_ATTRIB_TEX_COORDS Number readOnly

VERTEX_ATTRIB_MAX Number readOnly

UNIFORM_PMATRIX Number readOnly

UNIFORM_MVMATRIX Number readOnly

UNIFORM_MVPMATRIX Number readOnly

UNIFORM_TIME Number readOnly

UNIFORM_SINTIME Number readOnly

UNIFORM_COSTIME Number readOnly

UNIFORM_RANDOM01 Number readOnly

UNIFORM_SAMPLER Number readOnly

UNIFORM_MAX Number readOnly

SHADER_POSITION_TEXTURECOLOR String readOnly

SHADER_POSITION_TEXTURECOLORALPHATEST String readOnly

SHADER_POSITION_COLOR String readOnly

SHADER_POSITION_TEXTURE String readOnly

SHADER_POSITION_TEXTURE_UCOLOR String readOnly

SHADER_POSITION_TEXTUREA8COLOR String readOnly

SHADER_POSITION_UCOLOR String readOnly

SHADER_POSITION_LENGTHTEXTURECOLOR String readOnly

UNIFORM_PMATRIX_S String readOnly

UNIFORM_MVMATRIX_S String readOnly

UNIFORM_MVPMATRIX_S String readOnly

UNIFORM_TIME_S String readOnly

UNIFORM_SINTIME_S String readOnly

UNIFORM_COSTIME_S String readOnly

UNIFORM_RANDOM01_S String readOnly

UNIFORM_SAMPLER_S String readOnly

UNIFORM_ALPHA_TEST_VALUE_S String readOnly

ATTRIBUTE_NAME_COLOR String readOnly

ATTRIBUTE_NAME_POSITION String readOnly

ATTRIBUTE_NAME_TEX_COORD String readOnly

ITEM_SIZE Number readOnly

default size for font size

CURRENT_ITEM Number readOnly

default tag for current item

ZOOM_ACTION_TAG Number readOnly

default tag for zoom action tag

NORMAL_TAG Number readOnly

default tag for normal

SELECTED_TAG Number readOnly

default selected tag

DISABLE_TAG Number readOnly

default disabled tag

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

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

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

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

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

name type description
action ActionInterval
speed Number

returns:

type: Speed

follow
(
  • followedNode
  • rect
)
Follow | Null

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

name type description
followedNode Node
rect Rect

returns:

type: Follow | 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);

cardinalSplineTo
(
  • duration
  • points
  • tension
)
CardinalSplineTo

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:

type: CardinalSplineTo

examples:

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

cardinalSplineBy
(
  • duration
  • points
  • tension
)
CardinalSplineBy

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

name type description
duration Number
points Array
tension Number

returns:

type: CardinalSplineBy

catmullRomTo
(
  • dt
  • points
)
CatmullRomTo

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

name type description
dt Number
points Array

returns:

type: CatmullRomTo

examples:

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

catmullRomBy
(
  • dt
  • points
)
CatmullRomBy

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

name type description
dt Number
points Array

returns:

type: CatmullRomBy

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 =0.3]
)
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 optional Number 0.3

returns:

type: Object

examples:

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

easeElasticOut
(
  • [period =0.3]
)
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 optional Number 0.3

returns:

type: Object

examples:

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

easeElasticInOut
(
  • [period =0.3]
)
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 optional Number 0.3

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 ( ) Show

Show the Node.

returns:

type: Show

examples:

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

hide ( ) Hide

Hide the node.

returns:

type: Hide

examples:

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

toggleVisibility ( ) ToggleVisibility

Toggles the visibility of a node.

returns:

type: ToggleVisibility

examples:

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

removeSelf
(
  • [isNeedCleanUp =true]
)
RemoveSelf

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

name type description
isNeedCleanUp optional Boolean true

returns:

type: RemoveSelf

examples:

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

flipX
(
  • flip
)
FlipX

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:

type: FlipX

examples:

var flipXAction = cc.flipX(true);

flipY
(
  • flip
)
FlipY

Create a FlipY action to flip or unflip the target.

name type description
flip Boolean

returns:

type: FlipY

examples:

var flipYAction = cc.flipY(true);

place
(
  • pos
  • [y ]
)
Place

Creates a Place action with a position.

name type description
pos Vec2 | Number
y optional Number

returns:

type: Place

examples:

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

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

Creates the action with the callback

name type description
selector function
selectorTarget optional object | Null
data optional | Null

data for function, it accepts all data types.

returns:

type: CallFunc

examples:

// example
// CallFunc without data
var finish = cc.callFunc(this.removeSprite, this);

// CallFunc with data
var finish = cc.callFunc(this.removeFromParentAndCleanup, this._grossini,  true);

sequence
(
  • tempArray
)
Sequence

Helper constructor to create an array of sequenceable actions The created action will run actions sequentially, one after another.

name type description
tempArray Array | FiniteTimeAction

returns:

type: Sequence

examples:

// example
// create sequence with actions
var seq = cc.sequence(act1, act2);

// create sequence with array
var seq = cc.sequence(actArray);
todo: It should be use new

repeat
(
  • action
  • times
)
Repeat

Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30)

name type description
action FiniteTimeAction
times Number

returns:

type: Repeat

examples:

// example
var rep = cc.repeat(cc.sequence(jump2, jump1), 5);

repeatForever
(
  • action
)
RepeatForever

Create a acton which repeat forever

name type description
action FiniteTimeAction

returns:

type: RepeatForever

examples:

// example
var repeat = cc.repeatForever(cc.rotateBy(1.0, 360));

spawn
(
  • tempArray
)
FiniteTimeAction

Create a spawn action which runs several actions in parallel.

name type description
tempArray Array | FiniteTimeAction

returns:

examples:

// example
var action = cc.spawn(cc.jumpBy(2, cc.p(300, 0), 50, 4), cc.rotateBy(2, 720));
todo:It should be the direct use new

rotateTo
(
  • duration
  • deltaAngleX
  • [deltaAngleY ]
)
RotateTo

Rotates a Node object to a certain angle by modifying its rotation property.
The direction will be decided by the shortest angle.

name type description
duration Number

duration in seconds

deltaAngleX Number

deltaAngleX in degrees.

deltaAngleY optional Number

deltaAngleY in degrees.

returns:

type: RotateTo

examples:

// example
var rotateTo = cc.rotateTo(2, 61.0);

rotateBy
(
  • duration
  • deltaAngleX
  • [deltaAngleY ]
)
RotateBy

Rotates a Node object clockwise a number of degrees by modifying its rotation property. Relative to its properties to modify.

name type description
duration Number

duration in seconds

deltaAngleX Number

deltaAngleX in degrees

deltaAngleY optional Number

deltaAngleY in degrees

returns:

type: RotateBy

examples:

// example
var actionBy = cc.rotateBy(2, 360);

moveBy
(
  • duration
  • deltaPos
  • deltaY
)
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.

name type description
duration Number

duration in seconds

deltaPos Vec2 | Number
deltaY Number

returns:

type: MoveBy

examples:

// example
var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40));

moveTo
(
  • duration
  • position
  • y
)
MoveBy

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.

name type description
duration Number

duration in seconds

position Vec2
y Number

returns:

type: MoveBy

examples:

// example
var actionBy = cc.moveTo(2, cc.p(80, 80));

skewTo
(
  • t
  • sx
  • sy
)
SkewTo

Create a action which skews a Node object to given angles by modifying its skewX and skewY properties. Changes to the specified value.

name type description
t Number

time in seconds

sx Number
sy Number

returns:

type: SkewTo

examples:

// example
var actionTo = cc.skewTo(2, 37.2, -37.2);

skewBy
(
  • t
  • sx
  • sy
)
SkewBy

Skews a Node object by skewX and skewY degrees.
Relative to its property modification.

name type description
t Number

time in seconds

sx Number

sx skew in degrees for X axis

sy Number

sy skew in degrees for Y axis

returns:

type: SkewBy

examples:

// example
var actionBy = cc.skewBy(2, 0, -90);

jumpBy
(
  • duration
  • position
  • [y ]
  • height
  • jumps
)
JumpBy

Moves a Node object simulating a parabolic jump movement by modifying it's position property. Relative to its movement.

name type description
duration Number
position Vec2 | Number
y optional Number
height Number
jumps Number

returns:

type: JumpBy

examples:

// example
var actionBy = cc.jumpBy(2, cc.p(300, 0), 50, 4);
var actionBy = cc.jumpBy(2, 300, 0, 50, 4);

jumpTo
(
  • duration
  • position
  • [y ]
  • height
  • jumps
)
JumpTo

Moves a Node object to a parabolic position simulating a jump movement by modifying its position property.
Jump to the specified location.

name type description
duration Number
position Vec2 | Number
y optional Number
height Number
jumps Number

returns:

type: JumpTo

examples:

// example
var actionTo = cc.jumpTo(2, cc.p(300, 300), 50, 4);
var actionTo = cc.jumpTo(2, 300, 300, 50, 4);

bezierBy
(
  • t
  • c
)
BezierBy

An action that moves the target with a cubic Bezier curve by a certain distance. Relative to its movement.

name type description
t Number

time in seconds

c Array

Array of points

returns:

type: BezierBy

examples:

// example
var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)];
var bezierForward = cc.bezierBy(3, bezier);

bezierTo
(
  • t
  • c
)
BezierTo

An action that moves the target with a cubic Bezier curve to a destination point.

name type description
t Number
c Array

array of points

returns:

type: BezierTo

examples:

// example
var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)];
var bezierTo = cc.bezierTo(2, bezier);

scaleTo
(
  • duration
  • sx
  • [sy ]
)
ScaleTo

Scales a Node object to a zoom factor by modifying it's scale property.

name type description
duration Number
sx Number

scale parameter in X

sy optional Number

scale parameter in Y, if Null equal to sx

returns:

type: ScaleTo

examples:

// example
// It scales to 0.5 in both X and Y.
var actionTo = cc.scaleTo(2, 0.5);

// It scales to 0.5 in x and 2 in Y
var actionTo = cc.scaleTo(2, 0.5, 2);

scaleBy
(
  • duration
  • sx
  • [sy ]
)
ScaleBy

Scales a Node object a zoom factor by modifying it's scale property. Relative to its changes.

name type description
duration Number

duration in seconds

sx Number

sx scale parameter in X

sy optional Number | Null

sy scale parameter in Y, if Null equal to sx

returns:

type: ScaleBy

examples:

// example without sy, it scales by 2 both in X and Y
var actionBy = cc.scaleBy(2, 2);

//example with sy, it scales by 0.25 in X and 4.5 in Y
var actionBy2 = cc.scaleBy(2, 0.25, 4.5);

blink
(
  • duration
  • blinks
)
Blink

Blinks a Node object by modifying it's visible property.

name type description
duration Number

duration in seconds

blinks Unknown

blinks in times

returns:

type: Blink

examples:

// example
var action = cc.blink(2, 10);

fadeTo
(
  • duration
  • opacity
)
FadeTo

Fades an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from the current value to a custom one.

name type description
duration Number
opacity Number

0-255, 0 is transparent

returns:

type: FadeTo

examples:

// example
var action = cc.fadeTo(1.0, 0);

fadeIn
(
  • duration
)
FadeIn

Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255.

name type description
duration Number

duration in seconds

returns:

type: FadeIn

examples:

//example
var action = cc.fadeIn(1.0);

fadeOut
(
  • d
)
FadeOut

Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0.

name type description
d Number

duration in seconds

returns:

type: FadeOut

examples:

// example
var action = cc.fadeOut(1.0);

tintTo
(
  • duration
  • red
  • green
  • blue
)
TintTo

Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.

name type description
duration Number
red Number

0-255

green Number

0-255

blue Number

0-255

returns:

type: TintTo

examples:

// example
var action = cc.tintTo(2, 255, 0, 255);

tintBy
(
  • duration
  • deltaRed
  • deltaGreen
  • deltaBlue
)
TintBy

Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one. Relative to their own color change.

name type description
duration Number

duration in seconds

deltaRed Number
deltaGreen Number
deltaBlue Number

returns:

type: TintBy

examples:

// example
var action = cc.tintBy(2, -127, -255, -127);

delayTime
(
  • d
)
DelayTime

Delays the action a certain amount of seconds

name type description
d Number

duration in seconds

returns:

type: DelayTime

examples:

// example
var delay = cc.delayTime(1);

reverseTime
(
  • action
)
ReverseTime

Executes an action in reverse order, from time=duration to time=0.

name type description
action FiniteTimeAction

returns:

type: ReverseTime

examples:

// example
 var reverse = cc.reverseTime(this);

animate
(
  • animation
)
Animate

create the animate with animation

name type description
animation SpriteFrameAnimation

returns:

type: Animate

examples:

// example
// create the animation with animation
var anim = cc.animate(dance_grey);

targetedAction
(
  • target
  • action
)
TargetedAction

Create an action with the specified action and forced target

name type description
target Node
action FiniteTimeAction

returns:

type: TargetedAction

CGAffineToGL
(
  • trans
  • mat
)

convert an affine transform object to a kmMat4 object

name type description
trans cc.AffineTransform
mat cc.kmMat4

GLToCGAffine
(
  • mat
  • trans
)

Convert a kmMat4 object to an affine transform object

name type description
mat cc.kmMat4
trans cc.AffineTransform

isChildClassOf
(
  • subclass
  • superclass
)
Boolean

Checks whether subclass is child of superclass or equals to superclass

name type description
subclass Function
superclass Function

returns:

type: Boolean

associateWithNative
(
  • jsObj
  • superclass
)

Function added for JS bindings compatibility. Not needed in cocos2d-html5.

name type description
jsObj Object

subclass

superclass Object

getImageFormatByData
(
  • imgData
)
Number

get image format by image data

name type description
imgData Array

returns:

type: Number

inherits
(
  • childCtor
  • parentCtor
)

Another way to subclass: Using Google Closure. The following code was copied + pasted from goog.base / goog.inherits

name type description
childCtor Function
parentCtor Function

setAccelerometerEnabled
(
  • isEnable
)

whether enable accelerometer event

name type description
isEnable Boolean

setAccelerometerInterval
(
  • interval
)

set accelerometer interval value

name type description
interval Number

swap
(
  • x
  • y
  • ref
)
deprecated

deprecated: since v3.0

simple macro that swaps 2 variables
modified from c++ macro, you need to pass in the x and y variables names in string,
and then a reference to the whole object as third variable

name type description
x String
y String
ref Object

lerp
(
  • a
  • b
  • r
)

Linear interpolation between 2 numbers, the ratio sets how much it is biased to each end

name type description
a Number

number A

b Number

number B

r Number

ratio between 0 and 1

examples:

rand ( ) Number

get a random number from 0 to 0xffffff

returns:

type: Number

randomMinus1To1 ( ) Number

returns a random float between -1 and 1

returns:

type: Number

random0To1 ( ) Number

returns a random float between 0 and 1

returns:

type: Number

degreesToRadians
(
  • angle
)
Number

converts degrees to radians

name type description
angle Number

returns:

type: Number

radiansToDegrees
(
  • angle
)
Number

converts radians to degrees

name type description
angle Number

returns:

type: Number

radiansToDegress
(
  • angle
)
Number

converts radians to degrees

name type description
angle Number

returns:

type: Number

nodeDrawSetup
(
  • node
)

Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix

name type description
node Node

setup node

enableDefaultGLStates ( )

GL states that are enabled:
- GL_TEXTURE_2D
- GL_VERTEX_ARRAY
- GL_TEXTURE_COORD_ARRAY
- GL_COLOR_ARRAY

disableDefaultGLStates ( )

Disable default GL states:
- GL_TEXTURE_2D
- GL_TEXTURE_COORD_ARRAY
- GL_COLOR_ARRAY

incrementGLDraws
(
  • addNumber
)

Increments the GL Draws counts by one.
The number of calls per frame are displayed on the screen when the CCDirector's stats are enabled.

name type description
addNumber Number

contentScaleFactor ( ) Number

On Mac it returns 1;
On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1

returns:

type: Number

pointPointsToPixels
(
  • points
)
Vec2

Converts a Point in points to pixels

name type description
points Vec2

returns:

type: Vec2

pointPixelsToPoints
(
  • pixels
)
Vec2

Converts a Point in pixels to points

name type description
pixels Rect

returns:

type: Vec2

sizePointsToPixels
(
  • sizeInPoints
)
Size

Converts a Size in points to pixels

name type description
sizeInPoints Size

returns:

type: Size

sizePixelsToPoints
(
  • sizeInPixels
)
Size

Converts a size in pixels to points

name type description
sizeInPixels Size

returns:

type: Size

rectPixelsToPoints
(
  • pixel
)
Rect

Converts a rect in pixels to points

name type description
pixel Rect

returns:

type: Rect

rectPointsToPixels
(
  • point
)
Rect

Converts a rect in points to pixels

name type description
point Rect

returns:

type: Rect

checkGLErrorDebug ( )

Check webgl error.Error will be shown in console if exists.

deserialize
(
  • data
  • [result ]
  • [options ]
)
object

Deserialize json to cc.Asset

name type description
data (String | Object)

the serialized cc.Asset json string or json object.

result optional deserialize.Details

additional loading result

options optional Object

returns:

type: object

the main data(asset)

instantiate
(
  • original
)
Object

Clones the object original and returns the clone.

See Clone exists Entity

name type description
original Object

An existing object that you want to make a copy of.

returns:

type: Object

the newly instantiated object

find
(
  • path
  • [referenceNode ]
)
Node static

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.

name type description
path String
referenceNode optional Node

returns:

type: Node

the node or null if not found

Enum
(
  • obj
)
object

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.

name type description
obj object

a JavaScript literal object containing enum names and values

returns:

type: object

the defined enum type

examples:

Texture.WrapMode = cc.Enum({
Repeat: -1,
Clamp: -1
});
// Texture.WrapMode.Repeat == 0
// Texture.WrapMode.Clamp == 1
// Texture.WrapMode[0] == "Repeat"
// Texture.WrapMode[1] == "Clamp"

var FlagType = cc.Enum({
Flag1: 1,
Flag2: 2,
Flag3: 4,
Flag4: 8,
});
var AtlasSizeList = cc.Enum({
128: 128,
256: 256,
512: 512,
1024: 1024,
});

getList
(
  • enumDef
)
Object[] private

name type description
enumDef Object

the enum type defined from cc.Enum

returns:

type: Object[]

pNeg
(
  • point
)
Vec2

Returns opposite of point.

name type description
point Vec2

returns:

type: Vec2

pAdd
(
  • v1
  • v2
)
Vec2

Calculates sum of two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Vec2

pSub
(
  • v1
  • v2
)
Vec2

Calculates difference of two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Vec2

pMult
(
  • point
  • floatVar
)
Vec2

Returns point multiplied by given factor.

name type description
point Vec2
floatVar Number

returns:

type: Vec2

pMidpoint
(
  • v1
  • v2
)
PMult

Calculates midpoint between two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: PMult

pDot
(
  • v1
  • v2
)
Number

Calculates dot product of two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Number

pCross
(
  • v1
  • v2
)
Number

Calculates cross product of two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Number

pPerp
(
  • point
)
Vec2

Calculates perpendicular of v, rotated 90 degrees counter-clockwise -- cross(v, perp(v)) greater than 0

name type description
point Vec2

returns:

type: Vec2

pRPerp
(
  • point
)
Unknown

Calculates perpendicular of v, rotated 90 degrees clockwise -- cross(v, rperp(v)) smaller than 0

name type description
point Vec2

returns:

Vec2}

pProject
(
  • v1
  • v2
)
PMult

Calculates the projection of v1 over v2.

name type description
v1 Vec2
v2 Vec2

returns:

type: PMult

pRotate
(
  • v1
  • v2
)
Vec2

Rotates two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Vec2

pUnrotate
(
  • v1
  • v2
)
Vec2

Unrotates two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Vec2

pLengthSQ
(
  • v
)
Number

Calculates the square length of a cc.Vec2 (not calling sqrt() )

name type description
v Vec2

returns:

type: Number

pDistanceSQ
(
  • point1
  • point2
)
Number

Calculates the square distance between two points (not calling sqrt() )

name type description
point1 Vec2
point2 Vec2

returns:

type: Number

pLength
(
  • v
)
Number

Calculates distance between point an origin

name type description
v Vec2

returns:

type: Number

pDistance
(
  • v1
  • v2
)
Number

Calculates the distance between two points

name type description
v1 Vec2
v2 Vec2

returns:

type: Number

pNormalize
(
  • v
)
Vec2

Returns point multiplied to a length of 1.

name type description
v Vec2

returns:

type: Vec2

pForAngle
(
  • a
)
Vec2

Converts radians to a normalized vector.

name type description
a Number

returns:

type: Vec2

pToAngle
(
  • v
)
Number

Converts a vector to radians.

name type description
v Vec2

returns:

type: Number

clampf
(
  • value
  • min_inclusive
  • max_inclusive
)
Number

Clamp a value between from and to.

name type description
value Number
min_inclusive Number
max_inclusive Number

returns:

type: Number

clamp01
(
  • value
)
Number

Clamp a value between 0 and 1.

name type description
value Number

returns:

type: Number

pClamp
(
  • p
  • min_inclusive
  • max_inclusive
)
Vec2

Clamp a point between from and to.

name type description
p Point
min_inclusive Number
max_inclusive Number

returns:

type: Vec2

pFromSize
(
  • s
)
Vec2

Quickly convert cc.Size to a cc.Vec2.

name type description
s Size

returns:

type: Vec2

pCompOp
(
  • p
  • opFunc
)
Vec2

Run a math operation function on each point component
Math.abs, Math.fllor, Math.ceil, Math.round.

name type description
p Vec2
opFunc Function

returns:

type: Vec2

examples:

--------------
//For example: let's try to take the floor of x,y
var p = cc.pCompOp(cc.p(10,10),Math.abs);

pLerp
(
  • a
  • b
  • alpha
)
PAdd

Linear Interpolation between two points a and b. alpha == 0 ? a alpha == 1 ? b otherwise a value between a..b

name type description
a Vec2
b Vec2
alpha Number

returns:

type: PAdd

pFuzzyEqual
(
  • a
  • b
  • variance
)
Boolean

name type description
a Vec2
b Vec2
variance Number

returns:

type: Boolean

if points have fuzzy equality which means equal with some degree of variance.

pCompMult
(
  • a
  • b
)
Vec2

Multiplies a nd b components, a.xb.x, a.yb.y.

name type description
a Vec2
b Vec2

returns:

type: Vec2

pAngleSigned
(
  • a
  • b
)
Number

name type description
a Vec2
b Vec2

returns:

type: Number

the signed angle in radians between two vector directions

pAngle
(
  • a
  • b
)
Number

name type description
a Vec2
b Vec2

returns:

type: Number

the angle in radians between two vector directions

pRotateByAngle
(
  • v
  • pivot
  • angle
)
Vec2

Rotates a point counter clockwise by the angle around a pivot.

name type description
v Vec2

v is the point to rotate

pivot