Vector2
Two numbers, { x, y }, useful for screen or map positions. Arithmetic methods modify the vector and return it, so call clone() first if you still need the original.
vector2.zero()
Vector2.zero()(0, 0).
vector2.one()
Vector2.one()(1, 1).
vector2.set()
set(...values)Sets the components: set(x, y).
vector2.add()
add(other)Adds another vector to this one.
vector2.sub()
sub(other)Subtracts another vector from this one.
vector2.mul()
mul(scalar)Multiplies both components by a number.
vector2.div()
div(scalar)Divides both components by a number (not 0).
vector2.dot()
dot(other)The dot product with another vector.
vector2.lengthSquared
lengthSquaredThe length squared.
vector2.length
lengthThe vector's length.
vector2.normalize()
normalize()Scales this vector to length 1 (a zero vector stays zero).
vector2.lerp()
lerp(target, t)Moves this vector towards a target: t = 0 stays, 1 reaches it.
vector2.distance()
distance(other)The distance to another point.
vector2.clone()
clone()A copy.
vector2.x
x: numberThe first component.
vector2.y
y: numberThe second component.