Constructor
new Vector2(xopt, yopt)
- Source:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
x |
number
|
<optional>
|
0
|
the x coordinate of the vector |
y |
number
|
<optional>
|
0
|
the y coordinate of the vector |
Classes
- Vector2
Members
(readonly) ZERO :Vector2
- Description:
- A vector whose x and y values will remain 0.
- Source:
A vector whose x and y values will remain 0.
Type:
Methods
add(v)
- Description:
- Adds a given vector into this
- Source:
- Deprecated:
Parameters:
addScalar(n)
- Description:
- Adds a scalar value into this vector's
x and y values
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Description |
n |
number
|
|
clamp(minopt, maxopt) → {this}
- Description:
- Forces this vector to have a length
between the min and max.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
min |
number
|
<optional>
|
0
|
The smallest value
the length of this vector is allowed to have. |
max |
number
|
<optional>
|
1
|
The biggest value the length of this vector is allowed to have. |
Returns:
-
Type
-
this
clone()
- Description:
- Copies x and y values of this vector to
a new vector and returns the new vector.
- Source:
- Deprecated:
Returns:
Vector2
copy(v)
- Description:
- Copies x and y values of another vector
to this vector.
- Source:
- Deprecated:
Parameters:
Returns:
this
cross(v) → {number}
- Description:
- Calculates the cross product of two vectors.
- Source:
- Deprecated:
Parameters:
Returns:
-
Type
-
number
distanceTo(v)
- Source:
- Deprecated:
- Calculates length of this vector to another vector
Parameters:
| Name |
Type |
Description |
v |
Vector2
|
the other vector |
distanceToSquared(v) → {number}
- Description:
- Calculates length squared of this vector to another vector
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Description |
v |
Vector2
|
the other vector |
Returns:
-
Type
-
number
divide(n) → {this}
- Description:
- Divides this vector with a scalar.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Description |
n |
number
|
|
Returns:
-
Type
-
this
dot(v) → {number}
- Description:
- Calculates the dot product of two vectors.
- Source:
- Deprecated:
Parameters:
Returns:
-
Type
-
number
equals(v) → {boolean}
- Description:
- Checks to see if this vector is equal to
another vector.
- Source:
- Deprecated:
Parameters:
Returns:
-
Type
-
boolean
equalsZero() → {boolean}
- Description:
- Checks if the vector length is zero.
- Source:
- Deprecated:
Returns:
-
Type
-
boolean
magnitude() → {number}
- Source:
- Deprecated:
- Calculates length of this vector and returns
it
Returns:
-
Type
-
number
magnitudeSquared()
- Source:
- Deprecated:
- Calculates length squared of vector and returns it
multiply(n) → {this}
- Description:
- Multiplies this vector with a scalar.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Description |
n |
number
|
|
Returns:
-
Type
-
this
normal(l, targetopt) → {Vector2}
- Description:
- Returns a scaled vector normal to this vector,when scaled to 1,it returns a unit vector.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
l |
number
|
|
1
|
the length of the vector returned. |
target |
Vector2
|
<optional>
|
Vector2
|
Vector2 in which results are stored. |
Returns:
-
Type
-
Vector2
normalFast(targetopt) → {Vector2}
- Description:
- Returns the normal to a vector, the normal has the same length as the vector.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
target |
Vector2
|
<optional>
|
Vector2
|
Vector2 in which results are stored. |
Returns:
-
Type
-
Vector2
normalize() → {this}
- Description:
- Makes this vector a unit vector by
dividing its components with its length.
- Source:
- Deprecated:
Returns:
-
Type
-
this
reflect(normal, targetopt) → {Vector2}
- Description:
- Returns a vector of this reflected on a sirface perpendicular to the normal.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Attributes |
Description |
normal |
Vector2
|
|
the unit vector perpendicular to reflection surface |
target |
Vector2
|
<optional>
|
|
Returns:
-
Type
-
Vector2
reverse() → {this}
- Description:
- Negates the values of this vector.
- Source:
- Deprecated:
Returns:
-
Type
-
this
rotate(rad) → {this}
- Description:
- Rotates this vector by a given angle in radians.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Description |
rad |
number
|
Angle in radians |
Returns:
-
Type
-
this
rotateFast(cos, sin) → {this}
- Description:
- Rotates this vector by a given angle in radians.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Description |
cos |
number
|
|
sin |
number
|
|
Returns:
-
Type
-
this
set(x, y)
- Description:
- Sets x and y values of this vector to the given parameter.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Description |
x |
Number
|
|
y |
Number
|
|
setMagnitude(length)
- Source:
- Deprecated:
- Sets a vector to have the given length.
Parameters:
| Name |
Type |
Description |
length |
number
|
|
sub(v) → {this}
- Description:
- Subtracts a given vector from this vector
- Source:
- Deprecated:
Parameters:
Returns:
-
Type
-
this
subScalar(n) → {this}
- Description:
- Subtracts a scalar value from this vector's x and y values.
- Source:
- Deprecated:
Parameters:
| Name |
Type |
Description |
n |
number
|
|
Returns:
-
Type
-
this
toArray(targetopt)
- Source:
- Deprecated:
- Returns an array with x and y values of
this vector pushed into the array in
that order.
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
target |
Array.<number>
|
<optional>
|
[]
|
The array to
push values.Defaults to creating a new
array if not provided one |
Returns:
number[]
(static) absEqual(v1, v2)
- Source:
Parameters:
(static) add(v1, v2, outopt)
- Source:
Parameters:
(static) addScalar(v1, n, outopt)
- Source:
Parameters:
(static) clampMagnitude(v, min, max, out)
- Source:
Parameters:
(static) copy(v, outopt)
- Source:
Parameters:
(static) cross(v1, v2)
- Source:
Parameters:
(static) crossScalar(v1, n, out)
- Source:
Parameters:
(static) distanceTo(v1, v2)
- Source:
Parameters:
(static) distanceToSquared(v1, v2)
- Description:
- Calculates length squared of this vector to another vector
- Source:
Parameters:
(static) divide(v1, v2, outopt)
- Source:
Parameters:
(static) divideScalar(v1, n, outopt)
- Source:
Parameters:
(static) dot(v1, v2)
- Source:
Parameters:
(static) equal(v1, v2)
- Source:
Parameters:
(static) equalsZero(v)
- Source:
Parameters:
(static) fromAngle(radian, outopt) → {Vector2}
- Description:
- Returns a unit vector pointing in the
given angle starting from the positive x axis.
- Source:
Parameters:
| Name |
Type |
Attributes |
Description |
radian |
number
|
|
angle in radians from 0 to `Math.PI * 2` |
out |
Vector2
|
<optional>
|
Vector2 to store results in. |
Returns:
-
Type
-
Vector2
(static) getAbsAngleBetween(v1, v2) → {number}
- Description:
- Same as ` Vector2.getAbsDegBtwn` but returns in radians.
- Source:
Parameters:
| Name |
Type |
Description |
v1 |
Vector2
|
start of the angle |
v2 |
Vector2
|
end of the angle |
Returns:
-
Type
-
number
(static) getAbsDegBtwn(v1, v2) → {number}
- Description:
- Gets the angle (in degrees) between two
vectors in the range 0° to 360° in the anticlockwise direction from v1 to v2
- Source:
Parameters:
| Name |
Type |
Description |
v1 |
Vector2
|
start of the angle |
v2 |
Vector2
|
end of the angle |
Returns:
-
Type
-
number
(static) getAngleBetween(v1, v2) → {number}
- Description:
- Gets the angle (in radians) between two
vectors in the shortest direction from v1 to v2 in the range of `0` to `Math.PI`
- Source:
Parameters:
| Name |
Type |
Description |
v1 |
Vector2
|
start of the angle |
v2 |
Vector2
|
end of the angle |
Returns:
-
Type
-
number
(static) getDegBtwn(v1, v2) → {number}
- Description:
- Gets the angle (in degrees) between two
vectors in shortest direction from v1 to v2 in the range `0°` to `180°`
- Source:
Parameters:
| Name |
Type |
Description |
v1 |
Vector2
|
start of the angle |
v2 |
Vector2
|
end of the angle |
Returns:
-
Type
-
number
(static) lerp(v1, v2, t, outopt) → {Vector2}
- Description:
- Returns a Vector2 that has been lerped between v1 and v2
- Source:
Parameters:
| Name |
Type |
Attributes |
Description |
v1 |
Vector2
|
|
the vector to lerp from |
v2 |
Vector2
|
|
the vector to lerp from |
t |
number
|
|
a value from 0 to 1 to scale the new Vector2 between v1 and v2 |
out |
Vector2
|
<optional>
|
the vector to store results into |
Returns:
-
Type
-
Vector2
(static) magnitude(v)
- Source:
Parameters:
(static) magnitudeSquared(v)
- Source:
Parameters:
(static) multiply(v1, v2, outopt)
- Source:
Parameters:
(static) multiplyScalar(v1, n, outopt)
- Source:
Parameters:
(static) normal(v, out)
- Source:
Parameters:
(static) normalize(v, outopt)
- Source:
Parameters:
(static) random(outopt) → {Vector2}
- Description:
- Generates a new unit Vector2 in a random direction
- Source:
Parameters:
| Name |
Type |
Attributes |
Description |
out |
Vector2
|
<optional>
|
|
Returns:
-
Type
-
Vector2
(static) reflect(v, normal, outopt)
- Source:
Parameters:
(static) reverse(v, outopt)
- Source:
Parameters:
(static) rotate(v, angle, out)
- Source:
Parameters:
(static) rotateFast(v, cos, sin, out)
- Source:
Parameters:
(static) set(v, x, y)
- Source:
Parameters:
(static) setMagnitude(v, length)
- Source:
Parameters:
(static) sub(v1, v2, outopt)
- Source:
Parameters:
(static) subScalar(v1, n, outopt)
- Source:
Parameters:
(static) toAngle(v) → {number}
- Description:
- Returns the angle in radians between the positive x-axis and the vector.
- Source:
Parameters:
Returns:
-
Type
-
number