Class: Vector

Vector(x, y)

A Vector is a pair of values (x,y), useful for representing position (see Rectangle and Sprite).

Constructor

new Vector(x, y)

Set initial values for (x, y); defaults to (0, 0).
Parameters:
Name Type Default Description
x number 0 the x coordinate
y number 0 the y coordinate
Source:

Methods

addValues(dx, dy)

Add values to the x and y coordinates.
Parameters:
Name Type Description
dx number value to add to the x coordinate
dy number value to add to the y coordinate
Source:

addVector(other)

Add x and y components of another vector to this vector.
Parameters:
Name Type Description
other Vector vector to be added to this vector
Source:

getAngle() → {number}

Get the angle (in degrees) between this vector and the positive x-axis.
(Angles increase in clockwise direction, since positive y-axis is down.)
Source:
Returns:
angle between this vector and positive x-axis
Type
number

getLength() → {number}

Get the length of this vector.
Source:
Returns:
the length of this vector
Type
number

multiply(value)

Multiple x and y components of this vector by a constant.
Parameters:
Name Type Description
value number value to multiply by
Source:

setAngle(angleDegrees)

Set the angle (in degrees) between this vector and the positive x-axis (without changing the current length).
(Angles increase in clockwise direction, since positive y-axis is down.)
Parameters:
Name Type Description
angleDegrees number the new direction angle of this vector
Source:

setLength(length)

Set the length of this vector (without changing the current direction).
Parameters:
Name Type Description
length number new length of this vector
Source:

setValues(x, y)

Set new values for the x and y coordinates.
Parameters:
Name Type Description
x number new x coordinate
y number new y coordinate
Source: