Options
All
  • Public
  • Public/Protected
  • All
Menu
classdesc

Creates a Vector2

description

The Vector2 Class. Represents a point

since

2.0.0

Hierarchy

  • Vector2

Index

Constructors

constructor

  • new Vector2(x?: number, y?: number): Vector2

Properties

x

x: number = 0

y

y: number = 0

Accessors

Static DOWN

Static LEFT

Static RIGHT

Static UP

Static ZERO

Methods

abs

add

addNumber

  • memberof

    Vector2

    description

    Adds a number to the x and y properties

    since

    2.0.0

    Parameters

    • number: number

      Number to add to x and y properties

    Returns Vector2

angleBetween

  • angleBetween(vector: Vector2): number
  • memberof

    Vector2

    description

    Gets the angle between two Vector2s

    since

    2.0.0

    Parameters

    • vector: Vector2

      A Vector2 to get the angle between from

    Returns number

angleTo

  • memberof

    Vector2

    description

    Gets the angle to two Vector2s

    since

    2.0.0

    Parameters

    • vector: Vector2

      A Vector2 to get the angle to from

    Returns number

clamp

  • clamp(min: number, max: number): Vector2
  • memberof

    Vector2

    description

    Clamps the values to a min and max

    since

    2.0.0

    Parameters

    • min: number

      The min value

    • max: number

      The max value

    Returns Vector2

clampMax

clampMin

clone

crossProduct

  • crossProduct(vector: Vector2): number
  • memberof

    Vector2

    description

    Gets the cross dot product with another Vector2

    since

    2.0.0

    Parameters

    • vector: Vector2

      A Vector2 to get the cross dot product from

    Returns number

distance

  • memberof

    Vector2

    description

    Gets the distance from another Vector2

    since

    2.0.0

    Parameters

    • vector: Vector2

      A Vector2 to get the distance from

    Returns number

distanceSqr

  • distanceSqr(vector: Vector2): number
  • memberof

    Vector2

    description

    Gets the distance squared from another Vector2

    since

    2.0.0

    Parameters

    • vector: Vector2

      A Vector2 to get the distance from

    Returns number

divide

divideNumber

  • divideNumber(number: number): Vector2
  • memberof

    Vector2

    description

    Divides a number to the x and y properties

    since

    2.0.0

    Parameters

    • number: number

      Number to divide to x and y properties

    Returns Vector2

dot

  • memberof

    Vector2

    description

    Gets the dot product with another Vector2

    since

    2.0.0

    Parameters

    • vector: Vector2

      A Vector2 to get the dot product from

    Returns number

equals

  • memberof

    Vector2

    description

    Checks if another Vector2 is equal on both axises

    since

    2.0.0

    Parameters

    • vector: Vector2

      A Vector2 to compare with

    Returns boolean

getNormal

isZero

  • isZero(): boolean
  • memberof

    Vector2

    description

    Determines if Vector2.x and Vector2.y are both equal to 0

    since

    2.0.0

    Returns boolean

magnitude

  • magnitude(): number
  • memberof

    Vector2

    description

    Returns the magnitude or length of the Vector2

    since

    2.0.0

    Returns number

magnitudeSqr

  • magnitudeSqr(): number
  • memberof

    Vector2

    description

    Returns the magnitude/lenth squared of the Vector2

    since

    2.0.0

    Returns number

moveTowards

  • memberof

    Vector2

    description

    Gradually interpolates the Vector2 towards another Vector2 by an amount

    since

    2.0.0

    Parameters

    • current: Vector2

      The Current Vector

    • target: Vector2

      The Target Vector2

    • maxDistanceDelta: number

      The amount to increase by

    Returns Vector2

multiply

multiplyNumber

  • multiplyNumber(number: number): Vector2
  • memberof

    Vector2

    description

    Multiplies a number to the x and y properties

    since

    2.0.0

    Parameters

    • number: number

      Number to multiply to x and y properties

    Returns Vector2

negate

normalize

perpendicular

reflect

  • memberof

    Vector2

    description

    Reflects the Vector2, returns the opposite value on a number line

    example

    new Vector2(100, 50).reflect() // Vector2(-100, -50)

    since

    2.0.0

    Returns Vector2

rotate

  • memberof

    Vector2

    description

    Rotates the Vector2 based on degrees

    since

    2.0.0

    Parameters

    • degrees: number

      The angle in degrees

    • center: Vector2 = Vector2.ZERO

    Returns Vector2

round

scale

  • memberof

    Vector

    description

    Scales the Vector2 by a scalar Vector2

    since

    2.0.0

    Parameters

    • scalar: Vector2

      A Vector2 that is used to scale the current Vector2

    Returns Vector2

scaleToMagnitude

  • scaleToMagnitude(magnitude: number): Vector2
  • memberof

    Vector2

    description

    Scales the Vector2 by the magnitude or length

    since

    2.0.0

    Parameters

    • magnitude: number

      The magnitude or length of the Vector2

    Returns Vector2

setValues

  • setValues(x: number, y: number): Vector2
  • memberof

    Vector2

    description

    Sets the values of the Vector2

    since

    2.0.0

    Parameters

    • x: number

      X position to setValue of

    • y: number

      Y position to setValue of

    Returns Vector2

setValuesVec

  • memberof

    Vector2

    description

    Sets the values of the Vector2 based on another Vector2

    since

    2.0.0

    Parameters

    • vector: Vector2

      Vector2 to use to set the position

    Returns Vector2

subtract

subtractNumber

  • subtractNumber(number: number): Vector2
  • memberof

    Vector2

    description

    Subtracts a number from the x and y properties

    since

    2.0.0

    Parameters

    • number: number

      Number to subtract from x and y properties

    Returns Vector2

toPrecision

  • toPrecision(precision: number): Vector2
  • memberof

    Vector2

    description

    Sets the values to be precise by using Number.toPrecision

    since

    2.0.0

    Parameters

    • precision: number

      The precision

    Returns Vector2

toString

  • toString(): string
  • memberof

    Vector2

    description

    Returns the string version of the Vector2

    example

    console.log(new Vector2(0, 0).toString()) // Vector2(0, 0)

    since

    2.0.0

    Returns string

translate

  • translate(dx: number, dy: number): Vector2
  • memberof

    Vector2

    description

    Adds to the Vector2 by an amount

    since

    2.0.0

    Parameters

    • dx: number

      Delta x, the amount to increase the x value by

    • dy: number

      Delta y, the amount to increase the y value by

    Returns Vector2

translateX

  • memberof

    Vector2

    description

    Adds to the Vector2.x by an amount

    since

    2.0.0

    Parameters

    • dx: number

      Delta x, the amount to increase the x value by

    Returns Vector2

translateY

  • memberof

    Vector2

    description

    Adds to the Vector2.y by an amount

    since

    2.0.0

    Parameters

    • dy: number

      Delta y, the amount to increase the y value by

    Returns Vector2

tripleProduct

Static CREATE

  • CREATE(x?: number, y?: number): Vector2
  • memberof

    Vector2

    static
    description

    Returns a Vector2 with passed parameters, if no parameters are passed, a Vector2.ZERO is returned

    since

    2.0.0

    Parameters

    • Optional x: number
    • Optional y: number

    Returns Vector2

Static fromVec

  • memberof

    Vector2

    static
    description

    Returns a Vector2 with values from a passed Vector2

    since

    2.0.0

    Parameters

    • vector: Vector2

      Vector2 to create a Vector2 from

    Returns Vector2

Static fromVector2Like

  • memberof

    Vector2

    static
    description

    Returns a Vector2 with passed vector2Like object

    since

    2.0.0

    Parameters

    • vector2Like: Vector2Like

      An object with x and y properties

    Returns Vector2

Static toVector2Like

  • toVector2Like(vector2: Vector2): { x: number; y: number }
  • memberof

    Vector2

    static
    description

    Returns a Vector2Like object with passed Vector2

    since

    2.0.0

    Parameters

    • vector2: Vector2

      A Vector2 to convert to Vector2Like object

    Returns { x: number; y: number }

    • x: number
    • y: number

Generated using TypeDoc