PokéRogue
    Preparing search index...

    A representation of a vector in 2D space, defined by an x and y component.

    Vector2 is used throughout Phaser for positions, directions, velocities, and other quantities that have both magnitude and direction. It provides methods for common vector operations such as addition, subtraction, scaling, normalization, dot and cross products, linear interpolation, and rotation. Many Phaser APIs accept a Vector2Like object (any object with x and y number properties), making Vector2 easy to integrate across the framework.

    Index
    • Parameters

      • Optionalx: number | Vector2Like

        The x component, or an object with x and y properties. Default 0.

      • Optionaly: number

        The y component. Default x.

      Returns Vector2

    x: number

    The x component of this Vector.

    y: number

    The y component of this Vector.

    DOWN: Vector2

    A static down Vector2 for use by reference.

    This constant is meant for comparison operations and should not be modified directly.

    LEFT: Vector2

    A static left Vector2 for use by reference.

    This constant is meant for comparison operations and should not be modified directly.

    ONE: Vector2

    A static one Vector2 for use by reference.

    This constant is meant for comparison operations and should not be modified directly.

    RIGHT: Vector2

    A static right Vector2 for use by reference.

    This constant is meant for comparison operations and should not be modified directly.

    A static up Vector2 for use by reference.

    This constant is meant for comparison operations and should not be modified directly.

    ZERO: Vector2

    A static zero Vector2 for use by reference.

    This constant is meant for comparison operations and should not be modified directly.

    • Add a given Vector to this Vector. Addition is component-wise.

      Parameters

      Returns Vector2

      This Vector2.

    • Calculate the angle between this Vector and the positive x-axis, in radians.undefined

      Returns number

      The angle between this Vector, and the positive x-axis, given in radians.

    • Runs the x and y components of this Vector2 through Math.ceil and then sets them.undefined

      Returns Vector2

      This Vector2.

    • Make a clone of this Vector2.undefined

      Returns Vector2

      A clone of this Vector2.

    • Copy the components of a given Vector into this Vector.

      Parameters

      • src: Vector2Like

        The Vector to copy the components from.

      Returns Vector2

      This Vector2.

    • Calculate the cross product of this Vector and the given Vector.

      Parameters

      • src: Vector2Like

        The Vector2 to cross with this Vector2.

      Returns number

      The cross product of this Vector and the given Vector.

    • Calculate the distance between this Vector and the given Vector.

      Parameters

      • src: Vector2Like

        The Vector to calculate the distance to.

      Returns number

      The distance from this Vector to the given Vector.

    • Calculate the distance between this Vector and the given Vector, squared.

      Parameters

      • src: Vector2Like

        The Vector to calculate the distance to.

      Returns number

      The distance from this Vector to the given Vector, squared.

    • Perform a component-wise division between this Vector and the given Vector.

      Divides this Vector by the given Vector.

      Parameters

      • src: Vector2Like

        The Vector to divide this Vector by.

      Returns Vector2

      This Vector2.

    • Calculate the dot product of this Vector and the given Vector.

      Parameters

      • src: Vector2Like

        The Vector2 to dot product with this Vector2.

      Returns number

      The dot product of this Vector and the given Vector.

    • Check whether this Vector is equal to a given Vector.

      Performs a strict equality check against each Vector's components.

      Parameters

      • v: Vector2Like

        The vector to compare with this Vector.

      Returns boolean

      Whether the given Vector is equal to this Vector.

    • Runs the x and y components of this Vector2 through Math.floor and then sets them.undefined

      Returns Vector2

      This Vector2.

    • Check whether this Vector is approximately equal to a given Vector.

      Parameters

      • v: Vector2Like

        The vector to compare with this Vector.

      • Optionalepsilon: number

        The tolerance value. Default 0.0001.

      Returns boolean

      Whether both absolute differences of the x and y components are smaller than epsilon.

    • Swaps the x and y components of this Vector2.undefined

      Returns Vector2

      This Vector2.

    • Calculate the length (or magnitude) of this Vector.undefined

      Returns number

      The length of this Vector.

    • Calculate the length of this Vector squared.undefined

      Returns number

      The length of this Vector, squared.

    • Linearly interpolate between this Vector and the given Vector.

      Interpolates this Vector towards the given Vector.

      Parameters

      • src: Vector2Like

        The Vector2 to interpolate towards.

      • Optionalt: number

        The interpolation percentage, between 0 and 1. Default 0.

      Returns Vector2

      This Vector2.

    • Limit the length (or magnitude) of this Vector.

      Parameters

      • max: number

        The maximum length.

      Returns Vector2

      This Vector2.

    • Reflect this Vector across another.

      Parameters

      • axis: Vector2

        A vector to reflect across.

      Returns Vector2

      This Vector2.

    • Perform a component-wise multiplication between this Vector and the given Vector.

      Multiplies this Vector by the given Vector.

      Parameters

      • src: Vector2Like

        The Vector to multiply this Vector by.

      Returns Vector2

      This Vector2.

    • Negate the x and y components of this Vector.undefined

      Returns Vector2

      This Vector2.

    • Normalize this Vector.

      Makes the vector a unit length vector (magnitude of 1) in the same direction.undefined

      Returns Vector2

      This Vector2.

    • Rotate this Vector to its perpendicular, in the negative direction.undefined

      Returns Vector2

      This Vector2.

    • Rotate this Vector to its perpendicular, in the positive direction.undefined

      Returns Vector2

      This Vector2.

    • Project this Vector onto another.

      Parameters

      • src: Vector2

        The vector to project onto.

      Returns Vector2

      This Vector2.

    • Calculates the vector projection of this Vector2 onto the non-zero vecB. This is the orthogonal projection of this vector onto a straight line parallel to vecB.

      Parameters

      • vecB: Vector2

        The vector to project onto.

      • Optionalout: Vector2

        The Vector2 object to store the position in. If not given, a new Vector2 instance is created.

      Returns Vector2

      The out Vector2 containing the projected values.

    • Reflect this Vector off a line defined by a normal.

      Parameters

      • normal: Vector2

        A vector perpendicular to the line.

      Returns Vector2

      This Vector2.

    • Make this Vector the zero vector (0, 0).undefined

      Returns Vector2

      This Vector2.

    • Rotate this Vector by an angle amount.

      Parameters

      • delta: number

        The angle to rotate by, in radians.

      Returns Vector2

      This Vector2.

    • Scale this Vector by the given value.

      Parameters

      • value: number

        The value to scale this Vector by.

      Returns Vector2

      This Vector2.

    • Set the x and y components of this Vector to the given x and y values.

      Parameters

      • x: number

        The x value to set for this Vector.

      • Optionaly: number

        The y value to set for this Vector. Default x.

      Returns Vector2

      This Vector2.

    • Set the angle of this Vector.

      Parameters

      • angle: number

        The angle, in radians.

      Returns Vector2

      This Vector2.

    • Set the component values of this Vector from a given Vector2Like object.

      Parameters

      • obj: Vector2Like

        The object containing the component values to set for this Vector.

      Returns Vector2

      This Vector2.

    • Set the length (or magnitude) of this Vector.

      Parameters

      • length: number

        The new magnitude of this Vector.

      Returns Vector2

      This Vector2.

    • This method is an alias for Vector2.set.

      Parameters

      • x: number

        The x value to set for this Vector.

      • Optionaly: number

        The y value to set for this Vector. Default x.

      Returns Vector2

      This Vector2.

    • Sets the x and y components of this Vector from the given angle and length.

      Parameters

      • angle: number

        The angle from the positive x-axis, in radians.

      • Optionallength: number

        The distance from the origin. Default 1.

      Returns Vector2

      This Vector2.

    • Subtract the given Vector from this Vector. Subtraction is component-wise.

      Parameters

      • src: Vector2Like

        The Vector to subtract from this Vector.

      Returns Vector2

      This Vector2.

    • Transform this Vector with the given Matrix3.

      Parameters

      • mat: Matrix3

        The Matrix3 to transform this Vector2 with.

      Returns Vector2

      This Vector2.

    • Transform this Vector with the given Matrix4.

      Parameters

      • mat: Matrix4

        The Matrix4 to transform this Vector2 with.

      Returns Vector2

      This Vector2.