as3AStarWithGreenThread is a A* (A Star) implementation based on a green thread mechanism optimization. The green thread approach allows the lib to schedule chunks of code to run over the time, which avoids a high CPU spike and possible UI hang. The lib works on a grid, which is an instance of the Grid
class, that describes the environment. A grid node has a position in space, represented by x, y coordinates, and a boolean indicating if it is walkable.
After a grid is supplied to the lib, developers can query for paths. If a route is found, the lib returns an array containing all nodes that compose the path.
Sample
var _grid :Grid = new Grid(NUM_OF_COLS, NUM_OF_ROWS); for(var i:int = 0; i < NUM_OF_BLOCK; i++) { _grid.setWalkable(posx, posy, Math.random() <= 0.5); } _grid.setEndNode(xpos2, ypos2); _grid.setStartNode(xpos, ypos); var astar:AStar = new AStar(); var foudd:Boolean = astar.findPath(_grid); if(found) { var _path:Array = astar.path; }