X component of vector.
Y component of vector.
Static
downStatic
leftStatic
oneStatic
rightStatic
upStatic
zeroAdds given Vector2 or X, Y to this Vector2 components.
This reference
vector2.add(exampleVector);
vector2.add(x, y);
The Vector2 or X-coordinate
Optional
y: numberThe Y-coordinate (if x
isn't Vector2)
Returns distance between Vector2 or X, Y coordinate.
The distance between vectors
vector2.distance(exampleVector);
vector2.distance(0, 0);
The Vector2 or X-coordinate
Optional
y: numberThe Y-coordinate (if x
isn't Vector2)
Sets components to given Vector2 or X, Y.
This reference
vector2.set(exampleVector);
vector2.set(x, y);
The Vector2 or X-coordinate
Optional
y: numberThe Y-coordinate (if x
isn't Vector2)
Substracts given Vector2 or X, Y to this Vector2 components.
This reference
vector2.subtract(exampleVector);
vector2.subtract(x, y);
The Vector2 or X-coordinate
Optional
y: numberThe Y-coordinate (if x
isn't Vector2)
Static
EqualStatic
IsStatic
LerpPerforms Linear Interpolation on Vectors2 with given decimal midpoint
Vector2 after Linear Interpolation.
const a = new JSGL.Vector2(3, 9);
const b = new JSGL.Vector2(5, 2);
JSGL.Vector2.Lerp(a, b, 0); // (3, 9)
JSGL.Vector2.Lerp(a, b, 0.5); // (4, 5.5)
JSGL.Vector2.Lerp(a, b, 1); // (5, 2)
Static
MaxReturns the new Vector2 with maximum X and Y coordinates from first and second Vector2
The new Vector2 with maximum X and Y
const a = new JSGL.Vector2(3, 9);
const b = new JSGL.Vector2(5, 2);
const max = JSGL.Vector2.Max(a, b); // (5, 9)
Static
MinReturns the new Vector2 with minimum X and Y coordinates from first and second Vector2
The new Vector2 with minimum X and Y
const a = new JSGL.Vector2(3, 9);
const b = new JSGL.Vector2(5, 2);
const min = JSGL.Vector2.Min(a, b); // (3, 2)
Constructs a new Vector2 with the given components.