Cocos Creator API

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

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

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

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.

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

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

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

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

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 ]
)
ActionInterval

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 ]
)
ActionInterval

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

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:

examples:

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

moveTo
(
  • duration
  • position
  • y
)
ActionInterval

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:

examples:

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

skewTo
(
  • t
  • sx
  • sy
)
ActionInterval

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:

examples:

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

skewBy
(
  • t
  • sx
  • sy
)
ActionInterval

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:

examples:

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

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

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

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

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:

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

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:

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 ]
)
ActionInterval

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 ]
)
ActionInterval

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

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

name type description
duration Number

duration in seconds

blinks Number

blinks in times

returns:

examples:

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

fadeTo
(
  • duration
  • opacity
)
ActionInterval

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:

examples:

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

fadeIn
(
  • duration
)
ActionInterval

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

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

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:

examples:

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

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

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

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

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

targetedAction
(
  • target
  • action
)
ActionInterval

Create an action with the specified action and forced target.

name type description
target Node
action FiniteTimeAction

returns:

HashElement ( )

Constructor

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

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

Class
(
  • [options ]
)
Function

Defines a CCClass using the given specification, please see Class for details.

name type description
options optional Object

returns:

type: Function

the created class

examples:

// define base class
var Node = cc.Class();

// define sub class
var Sprite = cc.Class({
name: 'Sprite',
extends: Node,
ctor: function () {
this.url = "";
this.id = 0;
},

properties {
width: {
default: 128,
type: 'Integer',
tooltip: 'The width of sprite'
},
height: 128,
size: {
get: function () {
return cc.v2(this.width, this.height);
}
}
},

load: function () {
// load this.url
};
});

// instantiate

var obj = new Sprite();
obj.url = 'sprite.png';
obj.load();

// define static member

Sprite.count = 0;
Sprite.getBounds = function (spriteList) {
// ...
};

_isCCClass
(
  • constructor
)
Boolean private

Checks whether the constructor is created by cc.Class

name type description
constructor Function

returns:

type: Boolean

setAccelerometerEnabled
(
  • isEnable
)

whether enable accelerometer event

name type description
isEnable Boolean

setAccelerometerInterval
(
  • interval
)

set accelerometer interval value

name type description
interval Number

isValid
(
  • value
)
Boolean

Checks whether the object is non-nil and not yet destroyed.

name type description
value Any

returns:

type: Boolean

whether is valid

examples:

cc.log(cc.isValid(target));

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

color
(
  • [r =0]
  • [g =0]
  • [b =0]
  • [a =255]
)
Color

The convenience method to create a new cc.Color Alpha channel is optional. Default value is 255.

name type description
r optional Number 0
g optional Number 0
b optional Number 0
a optional Number 255

returns:

type: Color

examples:

-----------------------
// 1. All channels seperately as parameters
var color1 = new cc.Color(255, 255, 255, 255);
// 2. Convert a hex string to a color
var color2 = new cc.Color("#000000");
// 3. An color object as parameter
var color3 = new cc.Color({r: 255, g: 255, b: 255, a: 255});

colorEqual
(
  • color1
  • color2
)
Boolean

returns true if both ccColor3B are equal. Otherwise it returns false.

name type description
color1 Color
  • r Number optional , default: 0

    red component of the color, default value is 0.

  • g Number optional , default: 0

    green component of the color, defualt value is 0.

  • b Number optional , default: 0

    blue component of the color, default value is 0.

  • a Number optional , default: 255

    alpha component of the color, default value is 255.

color2 Color
  • r Number optional , default: 0

    red component of the color, default value is 0.

  • g Number optional , default: 0

    green component of the color, defualt value is 0.

  • b Number optional , default: 0

    blue component of the color, default value is 0.

  • a Number optional , default: 255

    alpha component of the color, default value is 255.

returns:

type: Boolean

true if both ccColor3B are equal. Otherwise it returns false.

examples:

cc.log(cc.colorEqual(cc.Color.RED, new cc.Color(255, 0, 0))); // true

hexToColor
(
  • hex
)
Color

convert a string of color for style to Color. e.g. "#ff06ff" to : cc.color(255,6,255)。

name type description
hex String

returns:

type: Color

examples:

cc.hexToColor("#FFFF33"); // Color {r: 255, g: 255, b: 51, a: 255};

colorToHex
(
  • color
)
String

convert Color to a string of color for style. e.g. cc.color(255,6,255) to : "#ff06ff"

name type description
color Color
  • r Number optional , default: 0

    red component of the color, default value is 0.

  • g Number optional , default: 0

    green component of the color, defualt value is 0.

  • b Number optional , default: 0

    blue component of the color, default value is 0.

  • a Number optional , default: 255

    alpha component of the color, default value is 255.

returns:

type: String

examples:

var color = new cc.Color(255, 6, 255)
cc.colorToHex(color); // #ff06ff;

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:

var 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 Vec2.

name type description
point Vec2

returns:

type: Vec2

examples:

cc.pNeg(cc.v2(10, 10));// Vec2 {x: -10, y: -10};

pAdd
(
  • v1
  • v2
)
Vec2

Calculates sum of two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Vec2

examples:

cc.pAdd(cc.v2(1, 1), cc.v2(2, 2));// Vec2 {x: 3, y: 3};

pSub
(
  • v1
  • v2
)
Vec2

Calculates difference of two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Vec2

examples:

cc.pSub(cc.v2(20, 20), cc.v2(5, 5)); // Vec2 {x: 15, y: 15};

pMult
(
  • point
  • floatVar
)
Vec2

Returns point multiplied by given factor.

name type description
point Vec2
floatVar Number

returns:

type: Vec2

examples:

cc.pMult(cc.v2(5, 5), 4); // Vec2 {x: 20, y: 20};

pMidpoint
(
  • v1
  • v2
)
Vec2

Calculates midpoint between two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Vec2

examples:

cc.pMidpoint(cc.v2(10, 10), cc.v2(5, 5)); // Vec2 {x: 7.5, y: 7.5};

pDot
(
  • v1
  • v2
)
Number

Calculates dot product of two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Number

examples:

cc.pDot(cc.v2(20, 20), cc.v2(5, 5)); // 200;

pCross
(
  • v1
  • v2
)
Number

Calculates cross product of two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Number

examples:

cc.pCross(cc.v2(20, 20), cc.v2(5, 5)); // 0;

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

examples:

cc.pPerp(cc.v2(20, 20)); // Vec2 {x: -20, y: 20};

pRPerp
(
  • point
)
Vec2

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

name type description
point Vec2

returns:

type: Vec2

examples:

cc.pRPerp(cc.v2(20, 20)); // Vec2 {x: 20, y: -20};

pProject
(
  • v1
  • v2
)
Vec2

Calculates the projection of v1 over v2.

name type description
v1 Vec2
v2 Vec2

returns:

type: Vec2

examples:

var v1 = cc.v2(20, 20);
var v2 = cc.v2(5, 5);
cc.pProject(v1, v2); // Vec2 {x: 20, y: 20};

pLengthSQ
(
  • v
)
Number

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

name type description
v Vec2

returns:

type: Number

examples:

cc.pLengthSQ(cc.v2(20, 20)); // 800;

pDistanceSQ
(
  • point1
  • point2
)
Number

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

name type description
point1 Vec2
point2 Vec2

returns:

type: Number

examples:

var point1 = cc.v2(20, 20);
var point2 = cc.v2(5, 5);
cc.pDistanceSQ(point1, point2); // 450;

pLength
(
  • v
)
Number

Calculates distance between point an origin.

name type description
v Vec2

returns:

type: Number

examples:

cc.pLength(cc.v2(20, 20)); // 28.284271247461902;

pDistance
(
  • v1
  • v2
)
Number

Calculates the distance between two points.

name type description
v1 Vec2
v2 Vec2

returns:

type: Number

examples:

var v1 = cc.v2(20, 20);
var v2 = cc.v2(5, 5);
cc.pDistance(v1, v2); // 21.213203435596427;

pNormalize
(
  • v
)
Vec2

Returns this vector with a magnitude of 1.

name type description
v Vec2

returns:

type: Vec2

examples:

cc.pNormalize(cc.v2(20, 20)); // Vec2 {x: 0.7071067811865475, y: 0.7071067811865475};

pForAngle
(
  • a
)
Vec2

Converts radians to a normalized vector.

name type description
a Number

returns:

type: Vec2

examples:

cc.pForAngle(20); // Vec2 {x: 0.40808206181339196, y: 0.9129452507276277};

pToAngle
(
  • v
)
Number

Converts a vector to radians.

name type description
v Vec2

returns:

type: Number

examples:

cc.pToAngle(cc.v2(20, 20)); // 0.7853981633974483;

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

examples:

var v1 = cc.clampf(20, 0, 20); // 20;
var v2 = cc.clampf(-1, 0, 20); //  0;
var v3 = cc.clampf(10, 0, 20); // 10;

clamp01
(
  • value
)
Number

Clamp a value between 0 and 1.

name type description
value Number

returns:

type: Number

examples:

var v1 = cc.clampf(20);  // 1;
var v2 = cc.clampf(-1);  // 0;
var v3 = cc.clampf(0.5); // 0.5;

pClamp
(
  • p
  • min_inclusive
  • max_inclusive
)
Vec2

Clamp a point between from and to.

name type description
p Vec2
min_inclusive Vec2
max_inclusive Vec2

returns:

type: Vec2

examples:

var min_inclusive = cc.v2(0, 0);
var max_inclusive = cc.v2(20, 20);
var v1 = cc.pClamp(cc.v2(20, 20), min_inclusive, max_inclusive); // Vec2 {x: 20, y: 20};
var v2 = cc.pClamp(cc.v2(0, 0), min_inclusive, max_inclusive);   // Vec2 {x: 0, y: 0};
var v3 = cc.pClamp(cc.v2(10, 10), min_inclusive, max_inclusive); // Vec2 {x: 10, y: 10};

pFromSize
(
  • s
)
Vec2

Quickly convert cc.Size to a cc.Vec2.

name type description
s Size

returns:

type: Vec2

examples:

cc.pFromSize(new cc.size(20, 20)); // Vec2 {x: 20, y: 20};

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:

cc.pCompOp(cc.p(-10, -10), Math.abs); // Vec2 {x: 10, y: 10};

pLerp
(
  • a
  • b
  • alpha
)
Vec2

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: Vec2

examples:

cc.pLerp(cc.v2(20, 20), cc.v2(5, 5), 0.5); // Vec2 {x: 12.5, y: 12.5};

pFuzzyEqual
(
  • a
  • b
  • variance
)
Boolean

TODO

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.

examples:

var a = cc.v2(20, 20);
var b = cc.v2(5, 5);
var b1 = cc.pFuzzyEqual(a, b, 10); // false;
var b2 = cc.pFuzzyEqual(a, b, 18); // true;

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

examples:

cc.pCompMult(acc.v2(20, 20), cc.v2(5, 5)); // Vec2 {x: 100, y: 100};

pAngleSigned
(
  • a
  • b
)
Number

TODO

name type description
a Vec2
b Vec2

returns:

type: Number

the signed angle in radians between two vector directions

pAngle
(
  • a
  • b
)
Number

TODO

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 Vec2

pivot is the pivot, naturally

angle Number

angle is the angle of rotation cw in radians

returns:

type: Vec2

the rotated point

pLineIntersect
(
  • A
  • B
  • C
  • D
  • retP
)
Boolean

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)),
retP.y is the range for a hitpoint in P3 (pa = p2 + t*(p4 - p3)).

returns:

type: Boolean

pSegmentIntersect
(
  • A
  • B
  • C
  • D
)
Boolean

ccpSegmentIntersect return YES if Segment A-B intersects with segment C-D.

name type description
A Vec2
B Vec2
C Vec2
D Vec2

returns:

type: Boolean

pIntersectPoint
(
  • A
  • B
  • C
  • D
)
Vec2

ccpIntersectPoint return the intersection point of line A-B, C-D.

name type description
A Vec2
B Vec2
C Vec2
D Vec2

returns:

type: Vec2

pSameAs
(
  • A
  • B
)
Boolean

check to see if both points are equal.

name type description
A Vec2

A ccp a

B Vec2

B ccp b to be compared

returns:

type: Boolean

the true if both ccp are same

pZeroIn
(
  • v
)

sets the position of the point to 0.

name type description
v Vec2

pIn
(
  • v1
  • v2
)

copies the position of one point to another.

name type description
v1 Vec2
v2 Vec2

pMultIn
(
  • point
  • floatVar
)

multiplies the point with the given factor (inplace).

name type description
point Vec2
floatVar Number

pSubIn
(
  • v1
  • v2
)

subtracts one point from another (inplace).

name type description
v1 Vec2
v2 Vec2

pAddIn
(
  • v1
  • v2
)

adds one point to another (inplace).

name type description
v1 Vec2
v2 Vec2

pNormalizeIn
(
  • v
)

normalizes the point (inplace).

name type description
v Vec2

rect
(
  • [x =0]
  • [y =0]
  • [w =0]
  • [h =0]
)
Rect

The convenience method to create a new Rect. see cc.Rect

name type description
x optional Number[] | Number 0
y optional Number 0
w optional Number 0
h optional Number 0

returns:

type: Rect

examples:

var a = new cc.rect(0 , 0, 10, 0);

rectEqualToRect
(
  • rect1
  • rect2
)
Boolean

Check whether a rect's value equals to another.

name type description
rect1 Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0
rect2 Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Boolean

examples:

var a = new cc.rect(0, 0, 10, 10);
var b = new cc.rect(0, 0, 5, 5);
cc.rectEqualToRect(a, b); // false;
var c = new cc.rect(0, 0, 5, 5);
cc.rectEqualToRect(b, c); // true;

rectContainsRect
(
  • rect1
  • rect2
)
Boolean

Check whether the rect1 contains rect2.

name type description
rect1 Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0
rect2 Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Boolean

examples:

var a = new cc.rect(0, 0, 20, 20);
var b = new cc.rect(10, 10, 20, 20);
cc.rectContainsRect(a, b); // true;

rectGetMaxX
(
  • rect
)
Number

Returns the rightmost x-value of a rect.

name type description
rect Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Number

The rightmost x value.

examples:

var a = new cc.rect(10, 0, 20, 20);
cc.rectGetMaxX(a); // 30;

rectGetMidX
(
  • rect
)
Number

Return the midpoint x-value of a rect.

name type description
rect Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Number

The midpoint x value.

examples:

var a = new cc.rect(10, 0, 20, 20);
cc.rectGetMidX(a); // 20;

rectGetMinX
(
  • rect
)
Number

Returns the leftmost x-value of a rect.

name type description
rect Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Number

The leftmost x value.

examples:

var a = new cc.rect(10, 0, 20, 20);
cc.rectGetMinX(a); // 10;

rectGetMaxY
(
  • rect
)
Number

Return the topmost y-value of a rect.

name type description
rect Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Number

The topmost y value.

examples:

var a = new cc.rect(0, 10, 20, 20);
cc.rectGetMaxY(a); // 30;

rectGetMidY
(
  • rect
)
Number

Return the midpoint y-value of `rect'.

name type description
rect Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Number

The midpoint y value.

examples:

var a = new cc.rect(0, 10, 20, 20);
cc.rectGetMidY(a); // 20;

rectGetMinY
(
  • rect
)
Number

Return the bottommost y-value of a rect.

name type description
rect Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Number

The bottommost y value.

examples:

var a = new cc.rect(0, 10, 20, 20);
cc.rectGetMinY(a); // 10;

rectContainsPoint
(
  • rect
  • point
)
Boolean

Check whether a rect contains a point.

name type description
rect Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0
point Vec2

returns:

type: Boolean

examples:

var a = new cc.rect(0, 10, 20, 20);
var b = cc.v2(0, 10, 10, 10);
cc.rectContainsPoint(a, b); // true;

rectIntersectsRect
(
  • rectA
  • rectB
)
Boolean

Check whether a rect intersect with another.

name type description
rectA Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0
rectB Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Boolean

examples:

var a = new cc.rect(0, 10, 20, 20);
var b = new cc.rect(0, 10, 10, 10);
cc.rectIntersectsRect(a, b); // true;

rectOverlapsRect
(
  • rectA
  • rectB
)
Boolean

Check whether a rect overlaps another.

name type description
rectA Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0
rectB Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Boolean

examples:

var a = new cc.rect(0, 10, 20, 20);
var b = new cc.rect(0, 10, 10, 10);
cc.rectOverlapsRect(a, b); // true;

rectUnion
(
  • rectA
  • rectB
)
Rect

Returns the smallest rectangle that contains the two source rectangles.

name type description
rectA Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0
rectB Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Rect

examples:

var a = new cc.rect(0, 10, 20, 20);
var b = new cc.rect(0, 10, 10, 10);
cc.rectUnion(a, b); // Rect {x: 0, y: 10, width: 20, height: 20};

rectUnion
(
  • rectA
  • rectB
)
Rect

Returns the overlapping portion of 2 rectangles.

name type description
rectA Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0
rectB Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Rect

examples:

var a = new cc.rect(0, 10, 20, 20);
var b = new cc.rect(0, 10, 10, 10);
cc.rectIntersection(a, b); // Rect {x: 0, y: 10, width: 10, height: 10};

V3F_C4B_T2F_QuadZero ( ) V3F_C4B_T2F_Quad

returns:

V3F_C4B_T2F_QuadCopy
(
  • sourceQuad
)
V3F_C4B_T2F_Quad

name type description
sourceQuad V3F_C4B_T2F_Quad

returns:

V3F_C4B_T2F_QuadsCopy
(
  • sourceQuads
)
Array

name type description
sourceQuads Array

returns:

type: Array

v2
(
  • [x =0]
  • [y =0]
)
Vec2

The convenience method to create a new cc.Vec2.

name type description
x optional Number | Object 0
y optional Number 0

returns:

type: Vec2

examples:

var v1 = cc.v2();
var v2 = cc.v2(0, 0);
var v3 = cc.v2(v2);
var v4 = cc.v2({x: 100, y: 100});

p
(
  • [x =0]
  • [y =0]
)
Vec2

The convenience method to creates a new cc.Vec2.

name type description
x optional Number | Object 0

a Number or a size object

y optional Number 0

returns:

type: Vec2

examples:

var point1 = cc.p();
var point2 = cc.p(100, 100);
var point3 = cc.p(point2);
var point4 = cc.p({x: 100, y: 100});

pointEqualToPoint
(
  • point1
  • point2
)
Boolean

Check whether a point's value equals to another.

name type description
point1 Vec2

!#en Constructor see Cc/vec2:method or cc.p !#zh 构造函数,可查看 Cc/vec2:method 或者 cc.p

  • x number optional , default: 0
  • y number optional , default: 0
point2 Vec2

!#en Constructor see Cc/vec2:method or cc.p !#zh 构造函数,可查看 Cc/vec2:method 或者 cc.p

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Boolean