Path

Used to store and keep track of a path. The Path holds an array of points and a counter to indicate the next one up. Whatever object is using the Path can call getDestination() with its updated position to get the next point in the path, and increment the counter if necessary.

Constructor

new Path(space, points)

Create a new Path.
Parameters:
NameTypeDescription
spaceSpaceThe space the Path is being used in
pointsArray.<Vec2>The points (Vec2) that will make up the Path

Methods

drawDebug(ctx)

Draw a visualization of the Path for debugging purposes. Will show each point with lines connecting them, and will show which points have been completed based on the counter.
Parameters:
NameTypeDescription
ctxCanvasRenderingContext2DCanvas context to draw on

getDestination(pos)

Get the next destination in the path, based on a specified current position. Will advance the counter and return the next point if the specified position is close enough.
Parameters:
NameTypeDescription
posVec2Position to check with
Returns:
Next point in path

getEnd() → {Vec2}

Get the last position in the path.
Returns:
Last path position
Type: 
Vec2