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:
src/plugins/path/Path.js line 18

Members

cacheKey : string

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

Type:
  • string
Source:
src/plugins/path/Path.js line 41

coordinateSystem : number

The coordinate system used by the Path.

Type:
  • number
Source:
src/plugins/path/Path.js line 31

game : Phaser.Game

A reference to the currently running game.

Type:
Source:
src/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.

Type:
  • string
Source:
src/plugins/path/Path.js line 46

loops : boolean

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

Type:
  • boolean
Source:
src/plugins/path/Path.js line 36

Methods

addPathPoint( [x] [, y] [, vx] [, vy] [, speed] [, data] [, index])

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.

Source:
src/plugins/path/Path.js line 205
Returns:

The PathPoint object that was created.

Type
Phaser.PathPoint

atEnd(index)

Is the given PathPoint index the end of this path?

Parameters:
Name Type Description
index number

The index of the PathPoint to test.

Source:
src/plugins/path/Path.js line 516
Returns:

true if index is the last point in this path.

Type
boolean

clone()

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

Source:
src/plugins/path/Path.js line 185
Returns:

The cloned Path.

Type
Phaser.Path

create(coordinateSystem [, loops])

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?

Source:
src/plugins/path/Path.js line 148
Returns:

This Path object.

Type
Phaser.Path

debug(ctx [, active])

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.

Source:
src/plugins/path/Path.js line 693
Returns:

This Path object.

Type
Phaser.Path

getControlPointsOnThisCurve(curve)

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.

Source:
src/plugins/path/Path.js line 343
Returns:

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

Type
array

getCurve( [index])

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.

Source:
src/plugins/path/Path.js line 429
Returns:

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

Type
Phaser.Hermite

getPathPoint(index, point)

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.

Source:
src/plugins/path/Path.js line 360
Returns:

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

Type
boolean

getPathPointReference(index)

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.

Source:
src/plugins/path/Path.js line 405
Returns:

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

Type
Phaser.PathPoint

getPointOnThisCurve(curve [, t])

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.

Source:
src/plugins/path/Path.js line 319
Returns:

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

Type
Phaser.Point

numPoints()

The total number of PathPoints in this Path.

Source:
src/plugins/path/Path.js line 536
Returns:

The total number of PathPoints in this Path.

Type
number

pointIndex(pathPoint)

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.

Source:
src/plugins/path/Path.js line 481
Returns:

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

Type
number

processData(follower, pathPointIndex, reversing)

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.

Source:
src/plugins/path/Path.js line 552
Returns:

The PathPoint that has been processed.

Type
Phaser.PathPoint

removePathPoint( [index])

Remove a PathPoint from this paths point list.

Parameters:
Name Type Argument Description
index number <optional>

The index of the PathPoint to remove.

Source:
src/plugins/path/Path.js line 240
Returns:

The removed PathPoint object.

Type
Phaser.PathPoint

setOffset(x, y)

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.

Source:
src/plugins/path/Path.js line 302
Returns:

This Path object.

Type
Phaser.Path

setPathPoint(index, x, y [, vx] [, vy])

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.

Source:
src/plugins/path/Path.js line 260
Returns:

A reference to the PathPoint object that was updated.

Type
Phaser.PathPoint

smooth()

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

Source:
src/plugins/path/Path.js line 628
Returns:

This Path object.

Type
Phaser.Path

toJSON()

Serializes this Path into a JSON object and returns it.

Source:
src/plugins/path/Path.js line 799
Returns:

A JSON object representing this Path.

Type
Object

translatePoints(point)

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.

Source:
src/plugins/path/Path.js line 284
Returns:

This Path object.

Type
Phaser.Path

phaser-ce@2.9.2 is on GitHub and NPM

Documentation generated by JSDoc 3.5.4 on 2017-11-09 using Tomorrow.