Phaser Class: Path

## Phaser. Path

#### new Path(game, type, loops)

  A Phaser.Path contains all the functions need to create and manipulate a single Path object.
  A Path is a list of PathPoint objects connected by Hermite curves.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `game` | Phaser.Game |  |  | A reference to the Phaser.Game instance.
  `type` | number | <optional> | Phaser.Path.CoordinateSystems.WORLD | The coordinate system used by the Path.
  `loops` | boolean | <optional> | false | Should this Path loop or not when a PathFollower reaches the end of it?

  Source - plugins/path/Path.js, line 18

### Members

#### cacheKey :string

  The key of the JSON file in the cache used to define this path.

  Source - plugins/path/Path.js, line 41

#### coordinateSystem :number

  The coordinate system used by the Path.

  Source - plugins/path/Path.js, line 31

#### game :Phaser.Game

  A reference to the currently running game.

  Source - plugins/path/Path.js, line 26

#### key :string

  The key of the object within the JSON data. Used if there are multiple paths per JSON file.

  Source - plugins/path/Path.js, line 46

#### loops :boolean

  Should this Path loop or not when a PathFollower reaches the end of it?

  Source - plugins/path/Path.js, line 36

### Methods

#### addPathPoint(x, y, vx, vy, speed, data, index) → {Phaser.PathPoint}

  Creates a new PathPoint object, relative to the path origin, and adds it to this path.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `x` | number | <optional> | 0 | The x position of the PathPoint.
  `y` | number | <optional> | 0 | The y position of the PathPoint.
  `vx` | number | <optional> | 0 | The vx tangent vector value of the PathPoint.
  `vy` | number | <optional> | 0 | The vy tangent vector value of the PathPoint.
  `speed` | number | <optional> | 1 | The speed value of the PathPoint.
  `data` | number | <optional> | {} | The data object
  `index` | number | <optional> | null | The index of the new path point. If not given, will add point to end of point list.

  ##### Returns:

  Phaser.PathPoint -

  The PathPoint object that was created.

  Source - plugins/path/Path.js, line 205

#### atEnd(index) → {boolean}

  Is the given PathPoint index the end of this path?

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `index` | number | The index of the PathPoint to test.

  ##### Returns:

  boolean -

  true if index is the last point in this path.

  Source - plugins/path/Path.js, line 516

#### clone() → {Phaser.Path}

  Clone this Path object. It clones the origin and points data.

  ##### Returns:

  Phaser.Path -

  The cloned Path.

  Source - plugins/path/Path.js, line 185

#### create(coordinateSystem, loops) → {Phaser.Path}

  Initialize a Path based on the given coordinate system.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `coordinateSystem` | number | string |  |  | The Phaser.Path.CoordinateSystems type to use.
  `loops` | boolean | <optional> | false | Should this Path loop or not when a PathFollower reaches the end of it?

  ##### Returns:

  Phaser.Path -

  This Path object.

  Source - plugins/path/Path.js, line 148

#### debug(ctx, active) → {Phaser.Path}

  Draw the path on given canvas context. Used for debugging.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `ctx` | CanvasContext2D |  |  | The canvas context to draw the path on.
  `active` | boolean | <optional> | false | Whether or not to highlight the active segments of this Path or not.

  ##### Returns:

  Phaser.Path -

  This Path object.

  Source - plugins/path/Path.js, line 693

#### getControlPointsOnThisCurve(curve) → {array}

  Gets the points on the curve representing the end points of the line segments that make up the curve.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `curve` | Phaser.Hermite | A Phaser.Hermite curve.

  ##### Returns:

  array -

  An array of points representing the end points of 10 line segments that make up the curve.

  Source - plugins/path/Path.js, line 343

#### getCurve(index) → {Phaser.Hermite}

  Get the curve from the given point index to the next.

  If the curve has been created previously, use that definition again, otherwise calculate it now.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `index` | number | <optional> | 0 | The index of the point in this path to get the curve from.

  ##### Returns:

  Phaser.Hermite -

  A new Hermite object representing the curve starting at the 'index' path point.

  Source - plugins/path/Path.js, line 429

#### getPathPoint(index, point) → {boolean}

  Get a PathPoint from this path. Automatically handles path looping.

  The values from the PathPoint are copied into the given PathPoint object, which must
  be a reference to a pre-existing PathPoint, as it's not returned by this method.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `index` | number | The index of the point in this path to get.
  `point` | Phaser.PathPoint | A PathPoint object into which the found point object is cloned.

  ##### Returns:

  boolean -

  false if the index is past the end of the path and it doesn't loop, otherwise true.

  Source - plugins/path/Path.js, line 360

#### getPathPointReference(index) → {Phaser.PathPoint}

  Get a reference to a PathPoint from this Path, handle path looping.

  NOTE: because this is a PathPoint reference, it does not take into account the coordinateSystem selected, it will be WORLD, or OFFSET unmodified

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `index` | number | The index of the point in this path to get.

  ##### Returns:

  Phaser.PathPoint -

  A reference to the PathPoint object in this Path, or null if index is out of range.

  Source - plugins/path/Path.js, line 405

#### getPointOnThisCurve(curve, t) → {Phaser.Point}

  Get a point on the the current Path curve.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `curve` | Phaser.Hermite |  |  | A Phaser.Hermite curve object.
  `t` | number | <optional> | 0 .. 1.0 | The distance on the curve to get the point from. Where 0 is the start of the curve, and 1 is the end.

  ##### Returns:

  Phaser.Point -

  A point containing the x and y values at the specified distance (t) value in the curve.

  Source - plugins/path/Path.js, line 319

#### pointIndex(pathPoint) → {number}

  Find the first matching PathPoint in this path.
  It works by taking the given PathPoint object, and then iterating through all points
  in this Path until it finds one with the same values, then returns the index to it.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `pathPoint` | Phaser.PathPoint | The PathPoint object that will have its values compared to all the points in this Path.

  ##### Returns:

  number -

  The index of the PathPoint in this Path if an equal match is found, or -1 if no match is found.

  Source - plugins/path/Path.js, line 481

#### processData(follower, pathPointIndex, reversing) → {Phaser.PathPoint}

  Process the data associated with a point on this Path.
  Used by Phaser.PathFollower objects as they pass each control point.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `follower` | Phaser.PathFollower | The PathFollower that is processing the data.
  `pathPointIndex` | number | The index of the path point to process.
  `reversing` | boolean | Whether or not the follower is traversing the path in reverse.

  ##### Returns:

  Phaser.PathPoint -

  The PathPoint that has been processed.

  Source - plugins/path/Path.js, line 552

#### removePathPoint(index) → {Phaser.PathPoint}

  Remove a PathPoint from this paths point list.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `index` | number | <optional> | The index of the PathPoint to remove.

  ##### Returns:

  Phaser.PathPoint -

  The removed PathPoint object.

  Source - plugins/path/Path.js, line 240

#### setOffset(x, y) → {Phaser.Path}

  Set the Path level offset which will affect all of this paths PathFollowers.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `x` | number | The x offset.
  `y` | number | The y offset.

  ##### Returns:

  Phaser.Path -

  This Path object.

  Source - plugins/path/Path.js, line 302

#### setPathPoint(index, x, y, vx, vy) → {Phaser.PathPoint}

  Set a PathPoint objects position and tangent vector.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `index` | number |  | The index of the PathPoint in this paths point list.
  `x` | number |  | The x coordinate of the PathPoint.
  `y` | number |  | The y coordinate of the PathPoint.
  `vx` | number | <optional> | The x coordinate of the tangent vector to create the curve from.
  `vy` | number | <optional> | The y coordinate of the tangent vector to create the curve from.

  ##### Returns:

  Phaser.PathPoint -

  A reference to the PathPoint object that was updated.

  Source - plugins/path/Path.js, line 260

#### smooth() → {Phaser.Path}

  If your Path has 3 points or more, this will walk through it and auto-smooth them out.
  Note: It ignores branches.

  ##### Returns:

  Phaser.Path -

  This Path object.

  Source - plugins/path/Path.js, line 628

#### toJSON() → {Object}

  Serializes this Path into a JSON object and returns it.

  ##### Returns:

  Object -

  A JSON object representing this Path.

  Source - plugins/path/Path.js, line 799

#### translatePoints(point) → {Phaser.Path}

  Translate all points in a path by the given point.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `point` | Phaser.Point | object | A Phaser.Point, or a Point-like Object with public `x` and `y` properties, that will be used to modify all points in this paths point list.

  ##### Returns:

  Phaser.Path -

  This Path object.

  Source - plugins/path/Path.js, line 284