This is a simple path data container. Basically a list of points that a FlxObject can follow. Also has code for drawing debug visuals. FlxTilemap.findPath() returns a path usable by FlxPath, but you can also just make your own, using the add() functions below or by creating your own array of points.

Every FlxObject has a path property which can make it move along specified array of way points. Usage example:

var path = new FlxPath();
var points:Array<FlxPoint> = [new FlxPoint(0, 0), new FlxPoint(100, 0)];
object.path = path;
path.start(points, 50, FORWARD);

You can also do this in one line:

object.path = new FlxPath().start([new FlxPoint(0, 0), new FlxPoint(100, 0)], 50, FORWARD);

...or using some more chaining:

object.path = new FlxPath().add(0, 0).add(100, 0).start(50, FORWARD);

If you are fine with the default values of start (speed, mode, auto-rotate) you can also do:

object.path = new FlxPath([new FlxPoint(0, 0), new FlxPoint(100, 0)]).start();

Constructor

@:haxe.warning("-WDeprecated")new(?nodes:Array<FlxPoint>)

Variables

@:value(0)read onlyangle:Float = 0

The angle in degrees between this object and the next node, where -90 is directly upward, and 0 is to the right.

@:value(0)angleOffset:Float = 0

The amount of degrees to offset from the path's angle, when autoRotate is true. To use flixel 4.11's autoRotate behavior, set this to 90, so there is no rotation at 0 degrees.

Available since

5.0.0

.

See also:

autoCenter:Bool

Deprecated: "path.autoCenter is deprecated, use centerMode"

Legacy method of alignment for the object following the path. If true, align the midpoint of the object on the path, else use the x, y position.

@:value(false)autoRotate:Bool = false

Whether the object's angle should be adjusted to the path angle during path follow behavior.

@:value(XY)axes:FlxAxes = XY

Whether to limit movement to certain axes.

@:value(CENTER)centerMode:FlxPathAnchorMode = CENTER

How to center the object on the path.

Available since

5.7.0

.

@:value(false)immovable:Bool = false

Whether to make the object immovable while active.

read onlynodeIndex:Int

Deprecated: "nodeIndex is deprecated, use nextIndex, instead"

Tracks which node of the path this object is currently moving toward.

@:value(0)speed:Float = 0

The speed at which the object is moving on the path. When an object completes a non-looping path circuit, the path's speed will be zeroed out, but the path reference will NOT be nulled out. So speed is a good way to check if this object is currently following a path or not.

onComplete:FlxPath ‑> Void

Deprecated: "onComplete is deprecated, use the onEndReached signal, instead"

Methods

add(x:Float, y:Float):FlxPath

Add a new node to the end of the path at the specified location.

Parameters:

x

X position of the new path point in world coordinates.

y

Y position of the new path point in world coordinates.

Returns:

This path object.

addAt(x:Float, y:Float, index:Int):FlxPath

Add a new node to the path at the specified location and index within the path.

Parameters:

x

X position of the new path point in world coordinates.

y

Y position of the new path point in world coordinates.

index

Where within the list of path nodes to insert this new point.

Returns:

This path object.

@:value({ asReference : false })addPoint(node:FlxPoint, asReference:Bool = false):FlxPath

Sometimes its easier or faster to just pass a point object instead of separate X and Y coordinates. This also gives you the option of not creating a new node but actually adding that specific FlxPoint object to the path. This allows you to do neat things, like dynamic paths.

Parameters:

node

The point in world coordinates you want to add to the path.

asReference

Whether to add the point as a reference, or to create a new point with the specified values.

Returns:

This path object.

@:value({ asReference : false })addPointAt(node:FlxPoint, index:Int, asReference:Bool = false):FlxPath

Sometimes its easier or faster to just pass a point object instead of separate X and Y coordinates. This also gives you the option of not creating a new node but actually adding that specific FlxPoint object to the path. This allows you to do neat things, like dynamic paths.

Parameters:

node

The point in world coordinates you want to add to the path.

index

Where within the list of path nodes to insert this new point.

asReference

Whether to add the point as a reference, or to create a new point with the specified values.

Returns:

This path object.

cancel():FlxPath

Stops the path's movement.

Returns:

This path object.

drawDebug(?camera:FlxCamera):Void

Deprecated: "FlxPath.debugDraw() is deprecated, use draw() OR drawDebugOnCamera(camera), instead"

While this doesn't override FlxBasic.drawDebug(), the behavior is very similar. Based on this path data, it draws a simple lines-and-boxes representation of the path if the drawDebug mode was toggled in the debugger overlay. You can use debugColor to control the path's appearance.

Parameters:

camera

The camera object the path will draw to.

head():FlxPoint

Get the first node in the list.

Returns:

The first node in the path.

remove(node:FlxPoint):FlxPoint

Remove a node from the path. NOTE: only works with points added by reference or with references from nodes itself!

Parameters:

node

The point object you want to remove from the path.

Returns:

The node that was excised. Returns null if the node was not found.

removeAt(index:Int):FlxPoint

Remove a node from the path using the specified position in the list of path nodes.

Parameters:

index

Where within the list of path nodes you want to remove a node.

Returns:

The node that was excised. Returns null if there were no nodes in the path.

reset():FlxPath

Just resets some debugging related variables (for debugger renderer). Also resets centerMode to CENTER.

Returns:

This path object.

restart():FlxPath

Restarts this path. So object starts movement again from the first (or last) path point (depends on path movement behavior mode).

Returns:

This path object.

setNode(nodeIndex:Int):FlxPath

Change the path node this object is currently at.

Parameters:

nodeIndex

The index of the new node out of path.nodes.

@:value({ autoRotate : false, mode : FlxPathType.FORWARD, speed : 100.0 })setProperties(speed:Float = 100.0, mode:FlxPathType = FlxPathType.FORWARD, autoRotate:Bool = false):FlxPath

Sets the following properties: speed, mode and auto rotation.

Parameters:

speed

The speed at which the object is moving on the path.

mode

Path following behavior (like looping, horizontal only, etc).

autoRotate

Whether the object's angle should be adjusted to the path angle during path follow behavior. Note that moving straight right is 0 degrees, when angle angleOffset is 0.

Returns:

This path object.

Available since

4.2.0

.

@:value({ nodesAsReference : false, autoRotate : false, mode : FlxPathType.FORWARD, speed : 100.0 })start(?nodes:Array<FlxPoint>, speed:Float = 100.0, mode:FlxPathType = FlxPathType.FORWARD, autoRotate:Bool = false, nodesAsReference:Bool = false):FlxPath

Starts movement along specified path.

Parameters:

nodes

An optional array of path waypoints. If null then previously added points will be used. Movement is not started if the resulting array has no points.

speed

The speed at which the object is moving on the path.

mode

Path following behavior (like looping, horizontal only, etc).

autoRotate

The object's angle should be adjusted to the path angle during path follow behavior.

nodesAsReference

To pass the input array as reference (true) or to copy the points (false). Default is false.

Returns:

This path object.

tail():FlxPoint

Get the last node in the list.

Returns:

The last node in the path.

Inherited Variables

Defined by FlxTypedBasePath

read onlycurrent:Null<FlxPoint>

The last node the target has reached

@:value(-1)read onlycurrentIndex:Int = -1

The index of the last node the target has reached, -1 means "no current node"

@:value({ })debugDrawData:FlxPathDrawData = { }

Specify a debug display color for the path. Default is WHITE.

@:value(FlxPathDirection.FORWARD)read onlydirection:FlxPathDirection = FlxPathDirection.FORWARD

The direction the list of nodes is being traversed. FORWARD leads to the last node

read onlyfinished:Bool

Whether this path is done, only true when loopType is ONCE

@:value(false)ignoreDrawDebug:Bool = false

Setting this to true will prevent the object from appearing when FlxG.debugger.drawDebug is true.

@:value(LOOP)loopType:FlxPathLoopType = LOOP

Behavior when the end(s) are reached

read onlynext:Null<FlxPoint>

The node the target is currently moving toward

@:value(-1)read onlynextIndex:Int = -1

The index of the node the target is currently moving toward, -1 means the path is finished

nodes:Array<FlxPoint>

The list of points that make up the path data

@:value(new FlxTypedSignal<(FlxTypedBasePath<TTarget>)>())read onlyonEndReached:FlxTypedSignal<FlxTypedBasePath<TTarget> ‑> Void> = new FlxTypedSignal<(FlxTypedBasePath<TTarget>)>()

Called whenenever the end is reached, for YOYO this means both ends

@:value(new FlxTypedSignal<(FlxTypedBasePath<TTarget>)>())read onlyonFinish:FlxTypedSignal<FlxTypedBasePath<TTarget> ‑> Void> = new FlxTypedSignal<(FlxTypedBasePath<TTarget>)>()

Called when the end is reached and loopType1 is ONCE`

@:value(new FlxTypedSignal<(FlxTypedBasePath<TTarget>)>())read onlyonNodeReached:FlxTypedSignal<FlxTypedBasePath<TTarget> ‑> Void> = new FlxTypedSignal<(FlxTypedBasePath<TTarget>)>()

Called whenenever any node reached

target:TTarget

The target traversing our path

read onlytotalNodes:Int

The length of the nodes array

Defined by FlxBasic

@:value(idEnumerator++)ID:Int = idEnumerator++

A unique ID starting from 0 and increasing by 1 for each subsequent FlxBasic that is created.

@:value(true)active:Bool = true

Controls whether update() is automatically called by FlxState/FlxGroup.

@:value(true)alive:Bool = true

Useful state for many game objects - "dead" (!alive) vs alive. kill() and revive() both flip this switch (along with exists, but you can override that).

camera:FlxCamera

Gets or sets the first camera of this object.

cameras:Array<FlxCamera>

This determines on which FlxCameras this object will be drawn. If it is null / has not been set, it uses the list of default draw targets, which is controlled via FlxG.camera.setDefaultDrawTarget as well as the DefaultDrawTarget argument of FlxG.camera.add.

read onlycontainer:Null<FlxContainer>

The parent containing this basic, typically if you check this recursively you should reach the state

Available since

5.7.0

.

@:value(true)exists:Bool = true

Controls whether update() and draw() are automatically called by FlxState/FlxGroup.

@:value(true)visible:Bool = true

Controls whether draw() is automatically called by FlxState/FlxGroup.

Inherited Methods

Defined by FlxTypedBasePath

drawDebugOnCamera(camera:FlxCamera):Void

Based on this path data, it draws a simple lines-and-boxes representation of the path if the drawDebug mode was toggled in the debugger overlay. You can use debugColor to control the path's appearance.

Parameters:

camera

The camera object the path will draw to.

getCameras():Array<FlxCamera>

Determines to which camera this will draw (or debug draw). The priority is from high to low: - Whatever value you've manually given the cameras or camera field - Any cameras drawing path's container, if one exists - Any cameras drawing path's target, if one exists - The default cameras

startAt(index:Int):FlxTypedBasePath<TTarget>

Change the path node this object is currently at.

Parameters:

index

The index of the new node out of path.nodes.

direction

Whether to head towards the head or the tail, if null the previous value is maintained

Defined by FlxBasic

getDefaultCamera():FlxCamera

The main camera that will draw this. Use this.cameras to set specific cameras for this object, otherwise the container's camera is used, or the container's container and so on. If there is no container, say, if this is inside FlxGroups rather than a FlxContainer then FlxG.camera is returned.

Available since

5.7.0

.

kill():Void

Handy function for "killing" game objects. Use reset() to revive them. Default behavior is to flag them as nonexistent AND dead. However, if you want the "corpse" to remain in the game, like to animate an effect or whatever, you should override this, setting only alive to false, and leaving exists true.

revive():Void

Handy function for bringing game objects "back to life". Just sets alive and exists back to true. In practice, this function is most often called by FlxObject#reset().