phaser - v4.0.0-rc.4
    Preparing search index...

    Defines a Line segment, a part of a line between two endpoints.

    Index

    Constructors

    • Parameters

      • Optionalx1: number

        The x coordinate of the lines starting point. Default 0.

      • Optionaly1: number

        The y coordinate of the lines starting point. Default 0.

      • Optionalx2: number

        The x coordinate of the lines ending point. Default 0.

      • Optionaly2: number

        The y coordinate of the lines ending point. Default 0.

      Returns Geom.Line

    Properties

    bottom: number

    The bottom position of the Line.

    left: number

    The left position of the Line.

    right: number

    The right position of the Line.

    top: number

    The top position of the Line.

    type: number

    The geometry constant type of this object: GEOM_CONST.LINE. Used for fast type comparisons.

    x1: number

    The x coordinate of the lines starting point.

    x2: number

    The x coordinate of the lines ending point.

    y1: number

    The y coordinate of the lines starting point.

    y2: number

    The y coordinate of the lines ending point.

    Methods

    • Get a point on a line that's a given percentage along its length.

      Type Parameters

      Parameters

      • position: number

        A value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line.

      • Optionaloutput: O

        An optional Vector2 object to store the coordinates of the point on the line.

      Returns O

    • Returns a Vector2 object that corresponds to the start of this Line.

      Type Parameters

      Parameters

      • Optionalvec2: O

        A Vector2 object to set the results in. If undefined a new Vector2 will be created.

      Returns O

    • Returns a Vector2 object that corresponds to the end of this Line.

      Type Parameters

      Parameters

      • Optionalvec2: O

        A Vector2 object to set the results in. If undefined a new Vector2 will be created.

      Returns O

    • Get a number of points along a line's length.

      Provide a quantity to get an exact number of points along the line.

      Provide a stepRate to ensure a specific distance between each point on the line. Set quantity to 0 when providing a stepRate.

      Type Parameters

      Parameters

      • quantity: number

        The number of points to place on the line. Set to 0 to use stepRate instead.

      • OptionalstepRate: number

        The distance between each point on the line. When set, quantity is implied and should be set to 0.

      • Optionaloutput: O

        An optional array of Vector2 objects to store the coordinates of the points on the line.

      Returns O

    • Sets this Line to match the x/y coordinates of the two given Vector2Like objects.

      Parameters

      • start: Vector2Like

        Any object with public x and y properties, whose values will be assigned to the x1/y1 components of this Line.

      • end: Vector2Like

        Any object with public x and y properties, whose values will be assigned to the x2/y2 components of this Line.

      Returns this

    • Set new coordinates for the line endpoints.

      Parameters

      • Optionalx1: number

        The x coordinate of the lines starting point. Default 0.

      • Optionaly1: number

        The y coordinate of the lines starting point. Default 0.

      • Optionalx2: number

        The x coordinate of the lines ending point. Default 0.

      • Optionaly2: number

        The y coordinate of the lines ending point. Default 0.

      Returns this

    • Using Bresenham's line algorithm this will return an array of all coordinates on this line.

      The start and end points are rounded before this runs as the algorithm works on integers.

      Parameters

      • line: Geom.Line

        The line.

      • OptionalstepRate: number

        The optional step rate for the points on the line. Default 1.

      • Optionalresults: Vector2Like[]

        An optional array to push the resulting coordinates into.

      Returns Vector2Like[]

    • Center a line on the given coordinates.

      Parameters

      • line: Geom.Line

        The line to center.

      • x: number

        The horizontal coordinate to center the line on.

      • y: number

        The vertical coordinate to center the line on.

      Returns Geom.Line

    • Copy the values of one line to a destination line.

      Type Parameters

      Parameters

      • source: Geom.Line

        The source line to copy the values from.

      • dest: O

        The destination line to copy the values to.

      Returns O

    • Extends the start and end points of a Line by the given amounts.

      The amounts can be positive or negative. Positive points will increase the length of the line, while negative ones will decrease it.

      If no right value is provided it will extend the length of the line equally in both directions.

      Pass a value of zero to leave the start or end point unchanged.

      Parameters

      • line: Geom.Line

        The line instance to extend.

      • left: number

        The amount to extend the start of the line by.

      • Optionalright: number

        The amount to extend the end of the line by. If not given it will be set to the left value.

      Returns Geom.Line

    • Returns an array of quantity Points where each point is taken from the given Line, spaced out according to the ease function specified.

      const line = new Phaser.Geom.Line(100, 300, 700, 300);
      const points = Phaser.Geom.Line.GetEasedPoints(line, 'sine.out', 32)

      In the above example, the points array will contain 32 points spread-out across the length of line, where the position of each point is determined by the Sine.out ease function.

      You can optionally provide a collinear threshold. In this case, the resulting points are checked against each other, and if they are < collinearThreshold distance apart, they are dropped from the results. This can help avoid lots of clustered points at far ends of the line with tightly-packed eases such as Quartic. Leave the value set to zero to skip this check.

      Note that if you provide a collinear threshold, the resulting array may not always contain quantity points.

      Type Parameters

      Parameters

      • line: Geom.Line

        The Line object.

      • ease: string | Function

        The ease to use. This can be either a string from the EaseMap, or a custom function.

      • quantity: number

        The number of points to return. Note that if you provide a collinearThreshold, the resulting array may not always contain this number of points.

      • OptionalcollinearThreshold: number

        An optional threshold. The final array is reduced so that each point is spaced out at least this distance apart. This helps reduce clustering in noisey eases. Default 0.

      • OptionaleaseParams: number[]

        An optional array of ease parameters to go with the ease.

      Returns O

    • Get the nearest point on a line perpendicular to the given point.

      Type Parameters

      Parameters

      • line: Geom.Line

        The line to get the nearest point on.

      • vec: Math.Vector2

        The Vector2 to get the nearest point to.

      • Optionalout: O

        An optional Vector2 object, to store the coordinates of the nearest point on the line.

      Returns O

    • Calculate the normal of the given line.

      The normal of a line is a vector that points perpendicular from it.

      Type Parameters

      Parameters

      • line: Geom.Line

        The line to calculate the normal of.

      • Optionalout: O

        An optional Vector2 object to store the normal in.

      Returns O

    • Get a point on a line that's a given percentage along its length.

      Type Parameters

      Parameters

      • line: Geom.Line

        The line.

      • position: number

        A value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line.

      • Optionalout: O

        An optional Vector2 object to store the coordinates of the point on the line.

      Returns O

    • Get a number of points along a line's length.

      Provide a quantity to get an exact number of points along the line.

      Provide a stepRate to ensure a specific distance between each point on the line. Set quantity to 0 when providing a stepRate.

      See also GetEasedPoints for a way to distribute the points across the line according to an ease type or input function.

      Type Parameters

      Parameters

      • line: Geom.Line

        The line.

      • quantity: number

        The number of points to place on the line. Set to 0 to use stepRate instead.

      • OptionalstepRate: number

        The distance between each point on the line. When set, quantity is implied and should be set to 0.

      • Optionalout: O

        An optional array of Vector2 objects to store the coordinates of the points on the line.

      Returns O

    • Get the shortest distance from a Line to the given Point.

      Parameters

      • line: Geom.Line

        The line to get the distance from.

      • point: Vector2Like

        The point to get the shortest distance to.

      Returns number | boolean

    • Get the angle of the normal of the given line in radians.

      Parameters

      • line: Geom.Line

        The line to calculate the angle of the normal of.

      Returns number

    • Returns the x component of the normal vector of the given line.

      Parameters

      • line: Geom.Line

        The Line object to get the normal value from.

      Returns number

    • The Y value of the normal of the given line. The normal of a line is a vector that points perpendicular from it.

      Parameters

      • line: Geom.Line

        The line to calculate the normal of.

      Returns number

    • Offset a line by the given amount.

      Type Parameters

      Parameters

      • line: O

        The line to offset.

      • x: number

        The horizontal offset to add to the line.

      • y: number

        The vertical offset to add to the line.

      Returns O

    • Calculate the perpendicular slope of the given line.

      Parameters

      • line: Geom.Line

        The line to calculate the perpendicular slope of.

      Returns number

    • Calculate the reflected angle between two lines.

      This is the outgoing angle based on the angle of Line 1 and the normalAngle of Line 2.

      Parameters

      Returns number

    • Rotate a line around its midpoint by the given angle in radians.

      Type Parameters

      Parameters

      • line: O

        The line to rotate.

      • angle: number

        The angle of rotation in radians.

      Returns O

    • Rotate a line around a point by the given angle in radians.

      Type Parameters

      Parameters

      • line: O

        The line to rotate.

      • point: Math.Vector2

        The point to rotate the line around.

      • angle: number

        The angle of rotation in radians.

      Returns O

    • Rotate a line around the given coordinates by the given angle in radians.

      Type Parameters

      Parameters

      • line: O

        The line to rotate.

      • x: number

        The horizontal coordinate to rotate the line around.

      • y: number

        The vertical coordinate to rotate the line around.

      • angle: number

        The angle of rotation in radians.

      Returns O

    • Set a line to a given position, angle and length.

      Type Parameters

      Parameters

      • line: O

        The line to set.

      • x: number

        The horizontal start position of the line.

      • y: number

        The vertical start position of the line.

      • angle: number

        The angle of the line in radians.

      • length: number

        The length of the line.

      Returns O