Vec2 Class

Extends ValueType

Module: cc Parent Module: cc

Representation of 2D vectors and points.

Index

Properties
  • ONE Vec2 return a Vec2 object with x = 1 and y = 1.
  • ZERO Vec2 return a Vec2 object with x = 0 and y = 0.
  • ZERO_R Vec2 return a readonly Vec2 object with x = 0 and y = 0.
  • UP Vec2 return a Vec2 object with x = 0 and y = 1.
  • UP Vec2 return a readonly Vec2 object with x = 0 and y = 1.
  • RIGHT Vec2 return a readonly Vec2 object with x = 1 and y = 0.
  • RIGHT_R Vec2 return a Vec2 object with x = 1 and y = 0.
  • x Number
  • y Number
Methods

Details

Properties

ONE

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

meta description
Type Vec2
Defined in cocos2d/core/value-types/vec2.ts:79
ZERO

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

meta description
Type Vec2
Defined in cocos2d/core/value-types/vec2.ts:89
ZERO_R

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

meta description
Type Vec2
Defined in cocos2d/core/value-types/vec2.ts:96
UP

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

meta description
Type Vec2
Defined in cocos2d/core/value-types/vec2.ts:105
UP

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

meta description
Type Vec2
Defined in cocos2d/core/value-types/vec2.ts:112

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

meta description
Type Vec2
Defined in cocos2d/core/value-types/vec2.ts:121
RIGHT_R

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

meta description
Type Vec2
Defined in cocos2d/core/value-types/vec2.ts:128
x
meta description
Type Number
Defined in cocos2d/core/value-types/vec2.ts:600
y
meta description
Type Number
Defined in cocos2d/core/value-types/vec2.ts:605

Methods

clone
meta description
Defined in cocos2d/core/value-types/vec2.ts:137
copy
meta description
Defined in cocos2d/core/value-types/vec2.ts:148
set
meta description
Defined in cocos2d/core/value-types/vec2.ts:161
add
meta description
Defined in cocos2d/core/value-types/vec2.ts:174
subtract
meta description
Defined in cocos2d/core/value-types/vec2.ts:187
multiply
meta description
Defined in cocos2d/core/value-types/vec2.ts:200
divide
meta description
Defined in cocos2d/core/value-types/vec2.ts:213
ceil
meta description
Defined in cocos2d/core/value-types/vec2.ts:226
ceil
meta description
Defined in cocos2d/core/value-types/vec2.ts:239
min
meta description
Defined in cocos2d/core/value-types/vec2.ts:252
max
meta description
Defined in cocos2d/core/value-types/vec2.ts:266
round
meta description
Defined in cocos2d/core/value-types/vec2.ts:279
multiplyScalar
meta description
Defined in cocos2d/core/value-types/vec2.ts:292
scaleAndAdd
meta description
Defined in cocos2d/core/value-types/vec2.ts:305
distance
meta description
Defined in cocos2d/core/value-types/vec2.ts:318
squaredDistance
meta description
Defined in cocos2d/core/value-types/vec2.ts:331
len
meta description
Defined in cocos2d/core/value-types/vec2.ts:344
lengthSqr
meta description
Defined in cocos2d/core/value-types/vec2.ts:357
negate
meta description
Defined in cocos2d/core/value-types/vec2.ts:370
inverse
meta description
Defined in cocos2d/core/value-types/vec2.ts:383
inverseSafe
meta description
Defined in cocos2d/core/value-types/vec2.ts:396
normalize
meta description
Defined in cocos2d/core/value-types/vec2.ts:422
dot
meta description
Defined in cocos2d/core/value-types/vec2.ts:441
cross
meta description
Defined in cocos2d/core/value-types/vec2.ts:452
lerp
meta description
Defined in cocos2d/core/value-types/vec2.ts:465
random
meta description
Defined in cocos2d/core/value-types/vec2.ts:480
transformMat3
meta description
Defined in cocos2d/core/value-types/vec2.ts:495
transformMat4
meta description
Defined in cocos2d/core/value-types/vec2.ts:511
strictEquals
meta description
Defined in cocos2d/core/value-types/vec2.ts:527
equals
meta description
Defined in cocos2d/core/value-types/vec2.ts:538
angle
meta description
Defined in cocos2d/core/value-types/vec2.ts:554
toArray
meta description
Defined in cocos2d/core/value-types/vec2.ts:574
fromArray
meta description
Defined in cocos2d/core/value-types/vec2.ts:587
constructor

Constructor see Cc/vec2:method or Cc/p:method

meta description
Defined in cocos2d/core/value-types/vec2.ts:613
Parameters
clone

clone a Vec2 object

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:635
set

Sets vector with another's value

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:645
Parameters
  • newValue Vec2 !#en new value to set. !#zh 要设置的新值
equals

Check whether two vector equal

meta description
Returns Boolean
Defined in cocos2d/core/value-types/vec2.ts:659
Parameters
fuzzyEquals

Check whether two vector equal with some degree of variance.

meta description
Returns Boolean
Defined in cocos2d/core/value-types/vec2.ts:670
Parameters
toString

Transform to string with vector informations

meta description
Returns string
Defined in cocos2d/core/value-types/vec2.ts:688
lerp

Calculate linear interpolation result between this vector and another one with given ratio

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:701
Parameters
  • to Vec2
  • ratio Number the interpolation coefficient
  • out Vec2 optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
clampf

Clamp the vector between from float and to float.

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:719
Parameters
Examples
var min_inclusive = cc.v2(0, 0);
var max_inclusive = cc.v2(20, 20);
var v1 = cc.v2(20, 20).clampf(min_inclusive, max_inclusive); // Vec2 {x: 20, y: 20};
var v2 = cc.v2(0, 0).clampf(min_inclusive, max_inclusive);   // Vec2 {x: 0, y: 0};
var v3 = cc.v2(10, 10).clampf(min_inclusive, max_inclusive); // Vec2 {x: 10, y: 10};
add

Adds this vector.

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:743
Parameters
Examples
var v = cc.v2(10, 10);
v.add(cc.v2(5, 5));// return Vec2 {x: 15, y: 15};
addSelf

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

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:762
Parameters
subtract

Subtracts one vector from this.

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:777
Parameters
Examples
var v = cc.v2(10, 10);
v.subSelf(cc.v2(5, 5));// return Vec2 {x: 5, y: 5};
multiply

Multiplies this by a number.

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:794
Parameters
Examples
var v = cc.v2(10, 10);
v.multiply(5);// return Vec2 {x: 50, y: 50};
multiply

Multiplies two vectors.

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:811
Parameters
Examples
var v = cc.v2(10, 10);
v.multiply(cc.v2(5, 5));// return Vec2 {x: 50, y: 50};
divide

Divides by a number.

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:828
Parameters
Examples
var v = cc.v2(10, 10);
v.divide(5); // return Vec2 {x: 2, y: 2};
negate

Negates the components.

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:845
Examples
var v = cc.v2(10, 10);
v.negate(); // return Vec2 {x: -10, y: -10};
dot

Dot product

meta description
Returns number
Defined in cocos2d/core/value-types/vec2.ts:861
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 cocos2d/core/value-types/vec2.ts:875
Parameters
Examples
var v = cc.v2(10, 10);
v.cross(cc.v2(5, 5)); // return 0;
len

Returns the length of this vector.

meta description
Returns number
Defined in cocos2d/core/value-types/vec2.ts:889
Examples
var v = cc.v2(10, 10);
v.len(); // return 14.142135623730951;
lengthSqr

Returns the squared length of this vector.

meta description
Returns number
Defined in cocos2d/core/value-types/vec2.ts:902
Examples
var v = cc.v2(10, 10);
v.lengthSqr(); // return 200;
normalizeSelf

Make the length of this vector to 1.

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:915
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 cocos2d/core/value-types/vec2.ts:941
Parameters
  • out Vec2 optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
angle

Get angle in radian between this and vector.

meta description
Returns number
Defined in cocos2d/core/value-types/vec2.ts:964
Parameters
signAngle

Get angle in radian between this and vector with direction.

meta description
Returns number
Defined in cocos2d/core/value-types/vec2.ts:986
Parameters
rotate

rotate

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:998
Parameters
  • radians number
  • out Vec2 optional, the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
rotateSelf

rotate self

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:1013
Parameters
project

Calculates the projection of the current vector over the given vector.

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:1030
Parameters
Examples
var v1 = cc.v2(20, 20);
var v2 = cc.v2(5, 5);
v1.project(v2); // Vec2 {x: 20, y: 20};
transformMat4

Transforms the vec2 with a mat4. 3rd vector component is implicitly '0', 4th vector component is implicitly '1'

meta description
Returns Vec2
Defined in cocos2d/core/value-types/vec2.ts:1045
Parameters
  • m Mat4 matrix to transform with
  • out Vec2 the receiving vector, you can pass the same vec2 to save result to itself, if not provided, a new vec2 will be created
maxAxis

Returns the maximum value in x, y.

meta description
Returns number
Defined in cocos2d/core/value-types/vec2.ts:1058

results matching ""

    No results matching ""