In HaxeFlixel 4 all FlxObjects have a path property which must be a FlxPath instance
class FlxObject extends FlxBasic
{
...
/**
* The path this object follows.
*/
public var path(default, set):FlxPath;
...
a tilemap can be used to find a path
var points:Array<FlxPoint> = tileMap.findPath(pathStart, pathEnd);
and then an object can walk that path
object.path = new FlxPath();
object.path.start(points);
What I want to do is run some custom code when the path ends, whether it was cancelled or was fully completed
what I see others do is this (player being the object in question)
override public function update(elapsed:Float):Void
{
if(Std.is(player.path, FlxPath)){
if (player.path.finished || player.path.nodes==null) {
trace('finished walking');
}
}
But this tends to run indefinitely once the player has finished walking, yet I want it to run once. Secondly I don't even want the PlayState update function to be aware that there was an event where the player finished walking, it's none of it's business unless I tell it that it happened, I want this code block to be self-contained.
I discovered that FlxPath has an onEnd function, which is exactly what I need, but it does not call any callback, neither are there any ways that I know of to attach it, there is also the onComplete property, but I was not able to make use of it.
so here is what I'd ideally like
object.path = new FlxPath();
object.path.start(points, function(cancelled){
trace((cancelled) ? 'path cancelled': 'path completed');
});
and this would run only once upon the path ending or getting cancelled
any ideas on some way of achieving this?