## `Vec2` 类型

### Details

meta description

meta description

meta description

meta description

meta description

meta description

#### 方法

meta description

meta description

##### set

meta description

###### 参数列表
• `newValue` Vec2 !#en new value to set. !#zh 要设置的新值
##### equals

meta description

###### 参数列表
• `other` Vec2
##### fuzzyEquals

meta description

###### 参数列表
• `other` Vec2
• `variance` Number

meta description

##### lerp

meta description

###### 参数列表
• `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

meta description

###### 参数列表
• `min_inclusive` Vec2
• `max_inclusive` Vec2
##### 示例
``````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};
``````

meta description

###### 参数列表
• `vector` Vec2
##### 示例
``````var v = cc.v2(10, 10);
v.addSelf(cc.v2(5, 5));// return Vec2 {x: 15, y: 15};
``````

meta description

###### 参数列表
• `vector` Vec2
• `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
##### 示例
``````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

meta description

###### 参数列表
• `vector` Vec2
##### 示例
``````var v = cc.v2(10, 10);
v.subSelf(cc.v2(5, 5));// return Vec2 {x: 5, y: 5};
``````
##### sub

meta description

###### 参数列表
• `vector` Vec2
• `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
##### 示例
``````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};
``````

meta description

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

meta description

###### 参数列表
• `num` 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
##### 示例
``````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

meta description

###### 参数列表
• `vector` Vec2
##### 示例
``````var v = cc.v2(10, 10);
v.scaleSelf(cc.v2(5, 5));// return Vec2 {x: 50, y: 50};
``````
##### scale

meta description

###### 参数列表
• `vector` Vec2
• `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
##### 示例
``````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};
``````

meta description

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

meta description

###### 参数列表
• `num` 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
##### 示例
``````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};
``````

meta description

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

meta description

###### 参数列表
• `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
##### 示例
``````var v = cc.v2(10, 10);
var v1;
v.neg(v1);  // return Vec2 {x: -10, y: -10};
``````
##### dot

meta description

###### 参数列表
• `vector` Vec2
##### 示例
``````var v = cc.v2(10, 10);
v.dot(cc.v2(5, 5)); // return 100;
``````
##### cross

meta description

###### 参数列表
• `vector` Vec2
##### 示例
``````var v = cc.v2(10, 10);
v.cross(cc.v2(5, 5)); // return 0;
``````

meta description

##### 示例
``````var v = cc.v2(10, 10);
v.mag(); // return 14.142135623730951;
``````

meta description

##### 示例
``````var v = cc.v2(10, 10);
v.magSqr(); // return 200;
``````

meta description

##### 示例
``````var v = cc.v2(10, 10);
v.normalizeSelf(); // return Vec2 {x: 0.7071067811865475, y: 0.7071067811865475};
``````
##### normalize

meta description

###### 参数列表
• `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

meta description

###### 参数列表
• `vector` Vec2
##### signAngle

meta description

###### 参数列表
• `vector` Vec2
##### rotate

meta description

###### 参数列表
• `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

meta description

###### 参数列表
• `radians` number
##### project

meta description

###### 参数列表
• `vector` Vec2
##### 示例
``````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

###### 参数列表
• `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