Hey everyone, Kino here. Today we’re showing off how to do pathing in Flixel. Yes, Flixel does have pathing out of the box. But, what is pathing, and how do we do it?
Pathing is self explanatory, it follows a set of points to the goal. This can be useful for setting up movement routes, patrol patterns following the player and more. By using pathing, we can even setup more intricate cut scenes or moving platforms in a game. These are all great uses of pathing. Now, how do we use it in our own code?
To use pathing, we have one option when it comes to FlxSprites. Every FlxSprite has a property on it for creating FlxPaths. This path property, allows you to create paths that a sprite can follow. All we have to do is pass it an array of FlxPoints. Here’s an example of me implementing it in my own game.
Here’s the result in game!
Pretty straight forward right? The cool thing is that they support different types of pathing such as forward, ping pong, backward, and so on. What that means is you could have the enemies in your game follow the path infinitely or maybe stop at the end or go back and forth between two points. A great tool to have when trying to create more complex game mechanics. The less code you have to write yourself the better, am I right?
With that said, good luck game making!! You can find the example project here!!
You can also play it here in the live example: Live Example.
If you have any questions, you can contact me on Twitter or subscribe to the blog for more tutorials on Haxe and Haxe Flixel!