as3pathfinder is a grid path finding library. It finds the shortest route from a start point to an end on a 2D grid for a given map of obstacles. The library uses the Dijkstra’s algorithm to calculate the route.
The grid used by the library can be described as a matrix, a two-dimensional array where obstacles are marked with 1 and the rest is marked as 0. The resulting route is described as an array of points.
Sample
var map:Array = [[0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0]]; var pt:Pathfinder = new Pathfinder(); pt.loadMap(map, 10, 10); var path:Array = pt.getPath(new Point(1, 1), new Point(8, 8), false); var myShape:Shape = new Shape(); addChild(myShape); myShape.graphics.lineStyle(2, 0x990000, 5); for (var i:int=0; i < path.length; i++) { trace(path[i].x, path[i].y) myShape.graphics.lineTo(path[i].x, path[i].y);; }
here, a great path finding lib build with crossbridge
http://www.adobe.com/devnet/games/articles/using-cplusplus-code-path-finding.html
Thanks! I’ll check that lib.
I guess actual link is https://github.com/azakhary/As3Pathfinder
It seems the author has moved to Github indeed, VirtualMaestro. Thanks for the link! I’ve updated the link and the license to reflect those changes.
hi
big thanks about this class, it’s a very nice,
may be there is a bit bug if you give this class endPoint(9,9) as example.
please clear this with all respect
Thanks
Hi there! I’m not the author of this lib, he is: https://github.com/azakhary
You can open an issue there reporting the bug you’ve found.