A* haXe pathfinding

November 26th, 2008 »

I rewrote bmod at BaseOneOnline.com’s Actionscript 3.0 A* classes to haXe (flash9 because I’m working on a game and needed some quick pathfinding. I also wanted to see if haXe would solve the A* algorithm faster than the adobe actionscript 3 compiler, and by how much. The benchmarks are not as accurate on bmod’s as3 because he mentions he used an inaccurate timing method. I had trouble with haXe’s flash9.utils.Timer class too, so i used the haXe haxe.Timer class to get a more accurate measurement.

The solved path is not always the shortest path possible as intended. But will suffice for what i need it for.

When sorting a node’s neighbors by it’s cost (distance), I had some trouble because i didn’t know how to translate AS3’s Array.sort) to haXe’s Array.sort. So i added DiskTree.net’s QuickSort (sorting the node property for distance “f”) to the com.baseoneonline.haxe.astar package.

Other than the timer and replacing Array.sort with QuickSort, the code is pretty much the same, just re-written to be compiled on haXe. There may be a few more enhancements i can make to make this faster, such as using Vector instead of Array and compiling for flash10, something i may try, or you can try and let me know :)

The original BaseOneOnline.com AS3 A* Article is here: http://blog.baseoneonline.com/?p=87

The exact Actionscript3 source that i used to convert to haXe:
BaseOneOnline-AStar-AS3.zip
Check the site though, he may have an update

My haXe‘d A* classes:
zipped: AStar-haXe.zip
svn: http://publicsvn.remixtechnology.com/AStar-haXe

Both examples have random “unwalkable” tiles generated, so just refresh this page to get a new random tile map. Just click around on the lighter tiles to find new paths

Original A* path finding in Actionscript 3 [Source][Destination]

You need Flash 10 to view the awesome. It’s a free and fast upgrade.

Ported A* path finding to haXe as3 [Source][Destination]

You need Flash 10 to view the awesome. It’s a free and fast upgrade.

i hope this fills your haXe tile based path finding needs well. Many thanks to bmod for his great work!


3 Responses to “A* haXe pathfinding”

Say Anything