melonjs
    Preparing search index...

    Class Vector2d

    a generic 2D Vector Object

    Index

    Constructors

    Properties

    x: number
    y: number

    Methods

    • Clamp this vector value within the specified value range

      Parameters

      • low: number

        minimum component value

      • high: number

        maximum component value

      Returns Vector2d

      Reference to this object for method chaining

    • Calculates the Euclidean distance between this vector and another vector.

      Parameters

      • v: Vector2d

        The vector to which the distance is calculated.

      Returns number

      The Euclidean distance between this vector and the given vector.

      let v1 = new Vector2d(3, 4);
      let v2 = new Vector2d(6, 8);
      v1.distance(v2); // returns 5
    • Checks if this vector is equal to another vector or a pair of coordinates.

      Parameters

      • ...args: [number, number] | [XYPoint | Vector2d]

        Either two numbers representing x and y coordinates or a single Vector2d object.

      Returns boolean

      True if the coordinates are equal, false otherwise.

      let v1 = new Vector2d(3, 4);
      let v2 = new Vector2d(3, 4);
      v1.equals(v2); // returns true
      let v = new Vector2d(3, 4);
      v.equals(3, 4); // returns true
    • interpolate the position of this vector towards the given one by the given maximum step.

      Parameters

      • target: Vector2d

        vector to rotate towards

      • step: number

        the maximum step per iteration (Negative values will push the vector away from the target)

      Returns Vector2d

      Reference to this object for method chaining

    • Multiply this vector values by the given scalar

      Parameters

      • x: number

        x scale value

      • Optionaly: number = x

        y scale value, if not passed, it uses the x value

      Returns Vector2d

      Reference to this object for method chaining

    • set the Vector x and y properties to the given values

      Parameters

      • x: number

        x component of the vector

      • y: number

        y component of the vector

      Returns Vector2d

      Reference to this object for method chaining

    • convert the object to a string representation

      Returns `x:${number},y:${number}`

      stringified representation of this vector