Using EasyStar.js 0.2.1 to find a path
An example of using EasyStar.js 0.2.1 to find a path.
var easystar = new EasyStar.js();
var level = [[0,0,1,0,0],
[1,0,1,0,1],
[0,0,1,0,0],
[0,0,1,1,0],
[0,0,0,0,0]];
easystar.setGrid(level);
easystar.setAcceptableTiles([0]);
easystar.enableDiagonals();
easystar.findPath(0, 0, 4, 0, function( path ) { // we are searching the shortest path from point (0,0) to the point (4,0)
if (path === null) {
console.log("The path to the destination point was not found.");
} else {
for (var i = 0; i < path.length; i++)
{
console.log("P: " + i + ", X: " + path[i].x + ", Y: " + path[i].y);
}
}
});
easystar.calculate();