baseoneaslib is a lib with a simple A-Star implementation. The path finding algorithm works within a graph defined by the developer and guided by two classes: TileGraph
and TileNode
. Every node in grid must be configured to indicate if it’s walkable or not.
Even though the lib provides its own implementation of a graph, which is a tile-based grid, it’s possible to use your own implementation using the Graph
interface. The graph doesn’t have to be a tile-based grid, which allows a high level of customization for your own needs.
Sample
var myGraph:TileGraph = new TileGraph(50,30); for (var x:int=0; x<50; x++) { for (var y:int=0; y<30; y++) { myGraph.setWalkable(x,y, /* walkable? */); } } var astar:AStar = new AStar(myGraph); var start:int = myGraph.getTileIndex(12, 4); var goal:int = myGraph.getTileIndex(33, 23); var path:Vector. = astar.solve(start, goal); var usablePath:Vector. = myGraph.getNodes(path);