Cocos Creator API

1.3.0

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

Vec2

Representation of 2D vectors and points.

ONE Vec2 static

return a Vec2 object with x = 1 and y = 1.

ZERO Vec2 static

return a Vec2 object with x = 0 and y = 0.

UP Vec2 static

return a Vec2 object with x = 0 and y = 1.

RIGHT Vec2 static

return a Vec2 object with x = 1 and y = 0.

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

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

Constructor see Cc/vec2:method or cc.p

x optional number 0
y optional number 0

:

: Vec2

clone ( ) Vec2

clone a Vec2 value

:

: Vec2

set
(
  • newValue
)
Vec2

TODO

newValue Vec2

!#en new value to set. !#zh 要设置的新值

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

:

: Vec2

returns this

equals
(
  • other
)
Boolean

TODO

other 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

:

toString ( ) string

TODO

:

: string

lerp
(
  • to
  • ratio
  • [out ]
)
Vec2

TODO

to 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
ratio number

the interpolation coefficient

out optional Vec2

optional, the receiving vector

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

:

: Vec2

addSelf
(
  • vector
)
Vec2

Adds this vector. If you want to save result to another vector, use add() instead.

vector 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

:

: Vec2

returns this

:

var v = cc.v2(10, 10);
v.addSelf(cc.v2(5, 5));// return Vec2 {x: 15, y: 15};

add
(
  • vector
  • [out ]
)
Vec2

Adds two vectors, and returns the new result.

vector 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
out optional Vec2

optional, the receiving vector

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

:

: Vec2

the result

:

var v = cc.v2(10, 10);
v.add(cc.v2(5, 5));      // return Vec2 {x: 15, y: 15};
var v1;
v.add(cc.v2(5, 5), v1);  // return Vec2 {x: 15, y: 15};

subSelf
(
  • vector
)
Vec2

Subtracts one vector from this. If you want to save result to another vector, use sub() instead.

vector 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

:

: Vec2

returns this

:

var v = cc.v2(10, 10);
v.subSelf(cc.v2(5, 5));// return Vec2 {x: 5, y: 5};

sub
(
  • vector
  • [out ]
)
Vec2

Subtracts one vector from this, and returns the new result.

vector 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
out optional Vec2

optional, the receiving vector

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

:

: Vec2

the result

:

var v = cc.v2(10, 10);
v.sub(cc.v2(5, 5));      // return Vec2 {x: 5, y: 5};
var v1;
v.sub(cc.v2(5, 5), v1);  // return Vec2 {x: 5, y: 5};

mulSelf
(
  • num
)
Vec2

Multiplies this by a number. If you want to save result to another vector, use mul() instead.

num number

:

: Vec2

returns this

:

var v = cc.v2(10, 10);
v.mulSelf(5);// return Vec2 {x: 50, y: 50};

mul
(
  • num
  • [out ]
)
Vec2

Multiplies by a number, and returns the new result.

num number
out optional Vec2

optional, the receiving vector

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

:

: Vec2

the result

:

var v = cc.v2(10, 10);
v.mul(5);      // return Vec2 {x: 50, y: 50};
var v1;
v.mul(5, v1);  // return Vec2 {x: 50, y: 50};

scaleSelf
(
  • vector
)
Vec2

Multiplies two vectors.

vector 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

:

: Vec2

returns this

:

var v = cc.v2(10, 10);
v.scaleSelf(cc.v2(5, 5));// return Vec2 {x: 50, y: 50};

scale
(
  • vector
  • [out ]
)
Vec2

Multiplies two vectors, and returns the new result.

vector 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
out optional Vec2

optional, the receiving vector

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

:

: Vec2

the result

:

var v = cc.v2(10, 10);
v.scale(cc.v2(5, 5));      // return Vec2 {x: 50, y: 50};
var v1;
v.scale(cc.v2(5, 5), v1);  // return Vec2 {x: 50, y: 50};

divSelf
(
  • vector
)
Vec2

Divides by a number. If you want to save result to another vector, use div() instead.

vector 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

:

: Vec2

returns this

:

var v = cc.v2(10, 10);
v.divSelf(5); // return Vec2 {x: 2, y: 2};

div
(
  • vector
  • [out ]
)
Vec2

Divides by a number, and returns the new result.

vector 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
out optional Vec2

optional, the receiving vector

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

:

: Vec2

the result

:

var v = cc.v2(10, 10);
v.div(5);      // return Vec2 {x: 2, y: 2};
var v1;
v.div(5, v1);  // return Vec2 {x: 2, y: 2};

negSelf ( ) Vec2

Negates the components. If you want to save result to another vector, use neg() instead.

:

: Vec2

returns this

:

var v = cc.v2(10, 10);
v.negSelf(); // return Vec2 {x: -10, y: -10};

neg
(
  • [out ]
)
Vec2

Negates the components, and returns the new result.

out optional Vec2

optional, the receiving vector