AStar类的getPath方法被用于获取从起点到终点的最短路径。
AStar.getPath(startNode, endNode, diagonalsAllowed)
startNode
:必需,起点节点对象。endNode
:必需,终点节点对象。diagonalsAllowed
:可选,布尔值,表示是否允许斜向移动。默认为false,即不允许。var startNode = new Node(0, 0);
var endNode = new Node(5, 5);
var astar = new AStar(map);
var path = astar.getPath(startNode, endNode);
if (path === null) {
console.log("No path found!");
} else {
console.log(path);
}