Module cc
The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace
Class
- DebugMode
- Action
- FiniteTimeAction
- ActionEase
- EaseRateAction
- EaseElastic
- EaseBounce
- ActionInstant
- ActionInterval
- AnimationClip
- SampledAnimCurve
- EventInfo
- EventAnimCurve
- AnimationState
- Playable
- WrapMode
- AnimationNode
- audioEngine
- HashElement
- ActionManager
- director
- game
- Node.EventType
- Node
- Scene
- ListEntry
- HashUpdateEntry
- HashTimerEntry
- Timer
- Scheduler
- pool
- Animation
- AudioSource
- Button.Transition
- Button.ClickEvent
- Button
- Canvas
- Component
- Label
- Layout.Type
- Layout.VerticalDirection
- Layout.HorizontalDirection
- Layout
- Mask
- ProgressBar.Mode
- ProgressBar
- Scrollbar.Direction
- Scrollbar
- ScrollView
- Sprite
- Widget
- Asset
- AudioClip
- BitmapFont
- Font
- Prefab
- RawAsset
- CoffeeScript
- SpriteAnimationAsset
- SpriteAtlas
- TTFFont
- TextAsset
- TiledMapAsset
- EventListener
- eventManager
- Event.EventMouse
- Event.EventTouch
- Event.EventFocus
- Event.EventAcceleration
- Event.EventKeyboard
- Touch
- EventTarget
- Event
- Event.EventCustom
- SpriteFrame
- spriteFrameCache
- AssetLibrary
- Class
- KEY
- view
- ContainerStrategy
- ContentStrategy
- EqualToFrame
- ProportionalToFrame
- EqualToWindow
- ProportionalToWindow
- OriginalContainer
- ResolutionPolicy
- UIOrientation
- inputManager
- loader
- screen
- sys
- visibleRect
- CallbacksInvoker
- Details
- url
- Texture2D.WrapMode
- Texture2D
- TextureAtlas
- textureCache
- AffineTransform
- Color
- Rect
- Size
- Acceleration
- BlendFunc
- FontDefinition
- SpriteType
- TextAlignment
- VerticalTextAlignment
- WebGLColor
- Vertex2F
- Vertex3F
- Tex2F
- Quad2
- Quad3
- V3F_C4B_T2F
- V3F_C4B_T2F_Quad
- V2F_C4B_T2F
- V2F_C4B_T2F_Triangle
- ValueType
- Vec2
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
)
- mode
Init Debug setting.
name | type | description |
---|---|---|
mode
|
DebugMode |
error
(
-
obj
-
subst
)
- 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
)
- 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
)
- 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
)
- 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
- action
- 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:
follow
(
-
followedNode
-
rect
)
Follow | Null
- followedNode
- rect
Create a follow action which makes its target follows another node.
returns:
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
- duration
- points
- tension
cardinalSplineBy
(
-
duration
-
points
-
tension
)
CardinalSplineBy
- duration
- points
- tension
catmullRomTo
(
-
dt
-
points
)
CatmullRomTo
- dt
- points
catmullRomBy
(
-
dt
-
points
)
CatmullRomBy
- dt
- points
easeIn
(
-
rate
)
Object
- rate
easeOut
(
-
rate
)
Object
- rate
easeInOut
(
-
rate
)
Object
- rate
easeExponentialIn ( ) Object
Creates the action easing object with the rate parameter.
Reference easeInExpo:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
// example
action.easing(cc.easeExponentialIn());
easeExponentialOut ( ) Object
creates the action easing object.
Reference easeOutExpo:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
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:
examples:
// example
action.easing(cc.easeExponentialInOut());
easeSineIn ( ) Object
creates an EaseSineIn action.
Reference easeInSine:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
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:
examples:
// example
action.easing(cc.easeSineOut());
easeSineInOut ( ) Object
creates the action easing object.
Reference easeInOutSine:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
// example
action.easing(cc.easeSineInOut());
easeElasticIn
(
-
[period
=0.3]
)
Object
- [period =0.3]
easeElasticOut
(
-
[period
=0.3]
)
Object
- [period =0.3]
easeElasticInOut
(
-
[period
=0.3]
)
Object
- [period =0.3]
easeBounceIn ( ) Object
Creates the action easing object.
Eased bounce effect at the beginning.
returns:
examples:
// example
action.easing(cc.easeBounceIn());
easeBounceOut ( ) Object
Creates the action easing object.
Eased bounce effect at the ending.
returns:
examples:
// example
action.easing(cc.easeBounceOut());
easeBounceInOut ( ) Object
Creates the action easing object.
Eased bounce effect at the begining and ending.
returns:
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:
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:
examples:
// example
action.easing(cc.easeBackOut());
easeBackInOut ( ) Object
Creates the action easing object.
Begining of cc.EaseBackIn. Ending of cc.EaseBackOut.
returns:
examples:
// example
action.easing(cc.easeBackInOut());
easeBezierAction
(
-
p0
-
p1
-
p2
-
p3
)
Object
- p0
- p1
- p2
- p3
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:
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:
examples:
//example
action.easing(cc.easeQuadraticActionIn());
easeQuadraticActionOut ( ) Object
Creates the action easing object.
Reference easeOutQuad:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeQuadraticActionOut());
easeQuadraticActionInOut ( ) Object
Creates the action easing object.
Reference easeInOutQuad:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeQuadraticActionInOut());
easeQuarticActionIn ( ) Object
Creates the action easing object.
Reference easeIntQuart:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeQuarticActionIn());
easeQuarticActionOut ( ) Object
Creates the action easing object.
Reference easeOutQuart:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.QuarticActionOut());
easeQuarticActionInOut ( ) Object
Creates the action easing object.
Reference easeInOutQuart:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
easeQuinticActionIn ( ) Object
Creates the action easing object.
Reference easeInQuint:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeQuinticActionIn());
easeQuinticActionOut ( ) Object
Creates the action easing object.
Reference easeOutQuint:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeQuadraticActionOut());
easeQuinticActionInOut ( ) Object
Creates the action easing object.
Reference easeInOutQuint:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeQuinticActionInOut());
easeCircleActionIn ( ) Object
Creates the action easing object.
Reference easeInCirc:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeCircleActionIn());
easeCircleActionOut ( ) Object
Creates the action easing object.
Reference easeOutCirc:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
easeCircleActionInOut ( ) Object
Creates the action easing object.
Reference easeInOutCirc:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeCircleActionInOut());
easeCubicActionIn ( ) Object
Creates the action easing object.
Reference easeInCubic:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeCubicActionIn());
easeCubicActionOut ( ) Object
Creates the action easing object.
Reference easeOutCubic:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
examples:
//example
action.easing(cc.easeCubicActionOut());
easeCubicActionInOut ( ) Object
Creates the action easing object.
Reference easeInOutCubic:
http://www.zhihu.com/question/21981571/answer/19925418
returns:
show ( ) Show
Show the Node.
returns:
examples:
// example
var showAction = cc.show();
hide ( ) Hide
Hide the node.
returns:
examples:
// example
var hideAction = cc.hide();
toggleVisibility ( ) ToggleVisibility
Toggles the visibility of a node.
returns:
examples:
// example
var toggleVisibilityAction = cc.toggleVisibility();
removeSelf
(
-
[isNeedCleanUp
=true]
)
RemoveSelf
- [isNeedCleanUp =true]
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:
examples:
// example
var removeSelfAction = cc.removeSelf();
flipX
(
-
flip
)
FlipX
- flip
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
)
FlipY
- flip
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
]
)
Place
- pos
- [y ]
callFunc
(
-
selector
-
[selectorTarget
]
-
[data
]
)
CallFunc
- selector
- [selectorTarget ]
- [data ]
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:
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
- tempArray
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:
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
- action
- times
Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30)
name | type | description |
---|---|---|
action
|
FiniteTimeAction | |
times
|
Number |
returns:
examples:
// example
var rep = cc.repeat(cc.sequence(jump2, jump1), 5);
repeatForever
(
-
action
)
RepeatForever
- action
Create a acton which repeat forever
name | type | description |
---|---|---|
action
|
FiniteTimeAction |
returns:
examples:
// example
var repeat = cc.repeatForever(cc.rotateBy(1.0, 360));
spawn
(
-
tempArray
)
FiniteTimeAction
- tempArray
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
- duration
- deltaAngleX
- [deltaAngleY ]
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:
examples:
// example
var rotateTo = cc.rotateTo(2, 61.0);
rotateBy
(
-
duration
-
deltaAngleX
-
[deltaAngleY
]
)
RotateBy
- duration
- deltaAngleX
- [deltaAngleY ]
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:
examples:
// example
var actionBy = cc.rotateBy(2, 360);
moveBy
(
-
duration
-
deltaPos
-
deltaY
)
MoveBy
- duration
- deltaPos
- deltaY
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.
returns:
examples:
// example
var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40));
moveTo
(
-
duration
-
position
-
y
)
MoveBy
- duration
- position
- y
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.
returns:
examples:
// example
var actionBy = cc.moveTo(2, cc.p(80, 80));
skewTo
(
-
t
-
sx
-
sy
)
SkewTo
- t
- sx
- sy
skewBy
(
-
t
-
sx
-
sy
)
SkewBy
- t
- sx
- sy
jumpBy
(
-
duration
-
position
-
[y
]
-
height
-
jumps
)
JumpBy
- duration
- position
- [y ]
- height
- jumps
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:
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
- duration
- position
- [y ]
- height
- jumps
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:
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
- t
- c
An action that moves the target with a cubic Bezier curve by a certain distance. Relative to its movement.
returns:
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
- t
- c
An action that moves the target with a cubic Bezier curve to a destination point.
returns:
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
- duration
- sx
- [sy ]
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:
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
- duration
- sx
- [sy ]
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:
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
- duration
- blinks
Blinks a Node object by modifying it's visible property.
name | type | description |
---|---|---|
duration
|
Number |
duration in seconds |
blinks
|
Unknown |
blinks in times |
returns:
examples:
// example
var action = cc.blink(2, 10);
fadeTo
(
-
duration
-
opacity
)
FadeTo
- duration
- opacity
fadeIn
(
-
duration
)
FadeIn
- duration
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:
examples:
//example
var action = cc.fadeIn(1.0);
fadeOut
(
-
d
)
FadeOut
- d
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:
examples:
// example
var action = cc.fadeOut(1.0);
tintTo
(
-
duration
-
red
-
green
-
blue
)
TintTo
- duration
- red
- green
- blue
tintBy
(
-
duration
-
deltaRed
-
deltaGreen
-
deltaBlue
)
TintBy
- duration
- deltaRed
- deltaGreen
- deltaBlue
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:
examples:
// example
var action = cc.tintBy(2, -127, -255, -127);
delayTime
(
-
d
)
DelayTime
- d
Delays the action a certain amount of seconds
name | type | description |
---|---|---|
d
|
Number |
duration in seconds |
returns:
examples:
// example
var delay = cc.delayTime(1);
reverseTime
(
-
action
)
ReverseTime
- action
Executes an action in reverse order, from time=duration to time=0.
name | type | description |
---|---|---|
action
|
FiniteTimeAction |
returns:
examples:
// example
var reverse = cc.reverseTime(this);
animate
(
-
animation
)
Animate
- animation
create the animate with animation
name | type | description |
---|---|---|
animation
|
SpriteFrameAnimation |
returns:
examples:
// example
// create the animation with animation
var anim = cc.animate(dance_grey);
targetedAction
(
-
target
-
action
)
TargetedAction
- target
- action
Create an action with the specified action and forced target
name | type | description |
---|---|---|
target
|
Node | |
action
|
FiniteTimeAction |
returns:
CGAffineToGL
(
-
trans
-
mat
)
- trans
- mat
convert an affine transform object to a kmMat4 object
name | type | description |
---|---|---|
trans
|
cc.AffineTransform | |
mat
|
cc.kmMat4 |
GLToCGAffine
(
-
mat
-
trans
)
- mat
- trans
Convert a kmMat4 object to an affine transform object
name | type | description |
---|---|---|
mat
|
cc.kmMat4 | |
trans
|
cc.AffineTransform |
isChildClassOf
(
-
subclass
-
superclass
)
Boolean
- subclass
- superclass
associateWithNative
(
-
jsObj
-
superclass
)
- jsObj
- superclass
getImageFormatByData
(
-
imgData
)
Number
- imgData
inherits
(
-
childCtor
-
parentCtor
)
- childCtor
- parentCtor
setAccelerometerEnabled
(
-
isEnable
)
- isEnable
whether enable accelerometer event
name | type | description |
---|---|---|
isEnable
|
Boolean |
setAccelerometerInterval
(
-
interval
)
- interval
set accelerometer interval value
name | type | description |
---|---|---|
interval
|
Number |
swap
(
-
x
-
y
-
ref
)
deprecated
- x
- y
- ref
lerp
(
-
a
-
b
-
r
)
- a
- b
- r
degreesToRadians
(
-
angle
)
Number
- angle
radiansToDegrees
(
-
angle
)
Number
- angle
radiansToDegress
(
-
angle
)
Number
- angle
nodeDrawSetup
(
-
node
)
- 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
)
- 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:
pointPointsToPixels
(
-
points
)
Vec2
- points
pointPixelsToPoints
(
-
pixels
)
Vec2
- pixels
sizePointsToPixels
(
-
sizeInPoints
)
Size
- sizeInPoints
sizePixelsToPoints
(
-
sizeInPixels
)
Size
- sizeInPixels
rectPixelsToPoints
(
-
pixel
)
Rect
- pixel
rectPointsToPixels
(
-
point
)
Rect
- point
checkGLErrorDebug ( )
Check webgl error.Error will be shown in console if exists.
deserialize
(
-
data
-
[result
]
-
[options
]
)
object
- data
- [result ]
- [options ]
instantiate
(
-
original
)
Object
- original
Clones the object original and returns the clone.
name | type | description |
---|---|---|
original
|
Object |
An existing object that you want to make a copy of. |
returns:
find
(
-
path
-
[referenceNode
]
)
Node
static
- path
- [referenceNode ]
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.
returns:
Enum
(
-
obj
)
object
- obj
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:
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
- enumDef
pAdd
(
-
v1
-
v2
)
Vec2
- v1
- v2
pSub
(
-
v1
-
v2
)
Vec2
- v1
- v2
pMult
(
-
point
-
floatVar
)
Vec2
- point
- floatVar
pMidpoint
(
-
v1
-
v2
)
PMult
- v1
- v2
pDot
(
-
v1
-
v2
)
Number
- v1
- v2
pCross
(
-
v1
-
v2
)
Number
- v1
- v2
pPerp
(
-
point
)
Vec2
- point
pRPerp
(
-
point
)
Unknown
- point
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
- v1
- v2
pRotate
(
-
v1
-
v2
)
Vec2
- v1
- v2
pUnrotate
(
-
v1
-
v2
)
Vec2
- v1
- v2
pLengthSQ
(
-
v
)
Number
- v
pDistanceSQ
(
-
point1
-
point2
)
Number
- point1
- point2
pLength
(
-
v
)
Number
- v
pDistance
(
-
v1
-
v2
)
Number
- v1
- v2
pNormalize
(
-
v
)
Vec2
- v
pForAngle
(
-
a
)
Vec2
- a
pToAngle
(
-
v
)
Number
- v
clampf
(
-
value
-
min_inclusive
-
max_inclusive
)
Number
- value
- min_inclusive
- max_inclusive
clamp01
(
-
value
)
Number
- value
pClamp
(
-
p
-
min_inclusive
-
max_inclusive
)
Vec2
- p
- min_inclusive
- max_inclusive
pFromSize
(
-
s
)
Vec2
- s
pCompOp
(
-
p
-
opFunc
)
Vec2
- p
- opFunc
pLerp
(
-
a
-
b
-
alpha
)
PAdd
- a
- b
- alpha
pFuzzyEqual
(
-
a
-
b
-
variance
)
Boolean
- a
- b
- variance
pCompMult
(
-
a
-
b
)
Vec2
- a
- b
pAngleSigned
(
-
a
-
b
)
Number
- a
- b
pAngle
(
-
a
-
b
)
Number
- a
- b
pRotateByAngle
(
-
v
-
pivot
-
angle
)
Vec2
- v
- pivot
- angle
pLineIntersect
(
-
A
-
B
-
C
-
D
-
retP
)
Boolean
- A
- B
- C
- D
- retP
A general line-line intersection test
indicating successful intersection of a line
note that to truly test intersection for segments we have to make
sure that s & t lie within [0..1] and for rays, make sure s & t > 0
the hit point is p3 + t * (p4 - p3);
the hit point also is p1 + s * (p2 - p1);
name | type | description |
---|---|---|
A
|
Vec2 |
A is the startpoint for the first line P1 = (p1 - p2). |
B
|
Vec2 |
B is the endpoint for the first line P1 = (p1 - p2). |
C
|
Vec2 |
C is the startpoint for the second line P2 = (p3 - p4). |
D
|
Vec2 |
D is the endpoint for the second line P2 = (p3 - p4). |
retP
|
Vec2 |
retP.x is the range for a hitpoint in P1 (pa = p1 + s*(p2 - p1)), |
returns:
pSegmentIntersect
(
-
A
-
B
-
C
-
D
)
Boolean
- A
- B
- C
- D
pIntersectPoint
(
-
A
-
B
-
C
-
D
)
Vec2
- A
- B
- C
- D
pSameAs
(
-
A
-
B
)
Boolean
- A
- B
pZeroIn
(
-
v
)
- v
sets the position of the point to 0.
name | type | description |
---|---|---|
v
|
Vec2 |
pMultIn
(
-
point
-
floatVar
)
- point
- floatVar
pAddIn
(
-
v1
-
v2
)
- v1
- v2
adds one point to another (inplace).
name | type | description |
---|---|---|
v1
|
Vec2 | |
v2
|
Point |
pNormalizeIn
(
-
v
)
- v
normalizes the point (inplace).
name | type | description |
---|---|---|
v
|
Vec2 |
V3F_C4B_T2F_QuadZero ( ) V3F_C4B_T2F_Quad
returns:
V3F_C4B_T2F_QuadCopy
(
-
sourceQuad
)
V3F_C4B_T2F_Quad
- sourceQuad
name | type | description |
---|---|---|
sourceQuad
|
V3F_C4B_T2F_Quad |
|
returns:
V3F_C4B_T2F_QuadsCopy
(
-
sourceQuads
)
Array
- sourceQuads
v2
(
-
[x
=0]
-
[y
=0]
)
Vec2
- [x =0]
- [y =0]
p
(
-
[x
=0]
-
[y
=0]
)
cc.Vec2
- [x =0]
- [y =0]