Vec2 Class

Extends ValueType

Module: cc Parent Module: cc

Representation of 2D vectors and points.

Index

Properties
  • x Number
  • y Number
  • ONE Vec2 return a Vec2 object with x = 1 and y = 1.
  • ZERO Vec2 return a Vec2 object with x = 0 and y = 0.
  • UP Vec2 return a Vec2 object with x = 0 and y = 1.
  • RIGHT Vec2 return a Vec2 object with x = 1 and y = 0.
Methods
  • constructor Constructor see Cc/vec2:method or cc.p
  • clone clone a Vec2 value
  • set TODO
  • equals TODO
  • toString TODO
  • lerp TODO
  • addSelf Adds this vector. If you want to save result to another vector, use add() instead.
  • add Adds two vectors, and returns the new result.
  • subSelf Subtracts one vector from this. If you want to save result to another vector, use sub() instead.
  • sub Subtracts one vector from this, and returns the new result.
  • mulSelf Multiplies this by a number. If you want to save result to another vector, use mul() instead.
  • mul Multiplies by a number, and returns the new result.
  • scaleSelf Multiplies two vectors.
  • scale Multiplies two vectors, and returns the new result.
  • divSelf Divides by a number. If you want to save result to another vector, use div() instead.
  • div Divides by a number, and returns the new result.
  • negSelf Negates the components. If you want to save result to another vector, use neg() instead.
  • neg Negates the components, and returns the new result.
  • dot Dot product
  • cross Cross product
  • mag Returns the length of this vector.
  • magSqr Returns the squared length of this vector.
  • normalizeSelf Make the length of this vector to 1.
  • normalize Returns this vector with a magnitude of 1.

    Note that the current vector is unchanged and a new normalized vector is returned. If you want to normalize the current vector, use normalizeSelf function.
  • angle Get angle in radian between this and vector.
  • signAngle Get angle in radian between this and vector with direction.
  • rotate rotate
  • rotateSelf rotate self

Details

Properties

x
meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:62
y
meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:65
ONE

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

meta description
Type Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:541
ZERO

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

meta description
Type Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:552
UP

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

meta description
Type Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:563

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

meta description
Type Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:574

Methods

constructor

Constructor see Cc/vec2:method or cc.p

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:41
Parameters
clone

clone a Vec2 value

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:72
set

TODO

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:82
Parameters
  • newValue Vec2 !#en new value to set. !#zh 要设置的新值
equals

TODO

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:96
Parameters
toString

TODO

meta description
Returns string
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:107
lerp

TODO

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:120
Parameters
  • to Vec2
  • ratio number the interpolation coefficient
  • out Vec2 optional, the receiving vector
addSelf

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

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:138
Parameters
Examples
var v = cc.v2(10, 10);
v.addSelf(cc.v2(5, 5));// return Vec2 {x: 15, y: 15};
add

Adds two vectors, and returns the new result.

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:155
Parameters
  • vector Vec2
  • out Vec2 optional, the receiving vector
Examples
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

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

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:175
Parameters
Examples
var v = cc.v2(10, 10);
v.subSelf(cc.v2(5, 5));// return Vec2 {x: 5, y: 5};
sub

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

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:192
Parameters
  • vector Vec2
  • out Vec2 optional, the receiving vector
Examples
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

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

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:212
Parameters
Examples
var v = cc.v2(10, 10);
v.mulSelf(5);// return Vec2 {x: 50, y: 50};
mul

Multiplies by a number, and returns the new result.

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:229
Parameters
  • num number
  • out Vec2 optional, the receiving vector
Examples
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

Multiplies two vectors.

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:249
Parameters
Examples
var v = cc.v2(10, 10);
v.scaleSelf(cc.v2(5, 5));// return Vec2 {x: 50, y: 50};
scale

Multiplies two vectors, and returns the new result.

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:266
Parameters
  • vector Vec2
  • out Vec2 optional, the receiving vector
Examples
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

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

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:286
Parameters
Examples
var v = cc.v2(10, 10);
v.divSelf(5); // return Vec2 {x: 2, y: 2};
div

Divides by a number, and returns the new result.

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:303
Parameters
  • vector Vec2
  • out Vec2 optional, the receiving vector
Examples
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

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

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:323
Examples
var v = cc.v2(10, 10);
v.negSelf(); // return Vec2 {x: -10, y: -10};
neg

Negates the components, and returns the new result.

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:339
Parameters
  • out Vec2 optional, the receiving vector
Examples
var v = cc.v2(10, 10);
var v1;
v.neg(v1);  // return Vec2 {x: -10, y: -10};
dot

Dot product

meta description
Returns number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:357
Parameters
Examples
var v = cc.v2(10, 10);
v.dot(cc.v2(5, 5)); // return 100;
cross

Cross product

meta description
Returns number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:371
Parameters
Examples
var v = cc.v2(10, 10);
v.cross(cc.v2(5, 5)); // return 0;
mag

Returns the length of this vector.

meta description
Returns number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:385
Examples
var v = cc.v2(10, 10);
v.mag(); // return 14.142135623730951;
magSqr

Returns the squared length of this vector.

meta description
Returns number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:398
Examples
var v = cc.v2(10, 10);
v.magSqr(); // return 200;
normalizeSelf

Make the length of this vector to 1.

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:411
Examples
var v = cc.v2(10, 10);
v.normalizeSelf(); // return Vec2 {x: 0.7071067811865475, y: 0.7071067811865475};
normalize

Returns this vector with a magnitude of 1.

Note that the current vector is unchanged and a new normalized vector is returned. If you want to normalize the current vector, use normalizeSelf function.

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:438
Parameters
  • out Vec2 optional, the receiving vector
angle

Get angle in radian between this and vector.

meta description
Returns number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:461
Parameters
signAngle

Get angle in radian between this and vector with direction.

meta description
Returns number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:483
Parameters
rotate

rotate

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:499
Parameters
  • radians number
  • out Vec2 optional, the receiving vector
rotateSelf

rotate self

meta description
Returns Vec2
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/value-types/CCVec2.js:514
Parameters

results matching ""

    No results matching ""