Description

(>= 1.3.0) Find the shortest path. Using the library Pathfinding.js. The array must contain only the value 0 or 1. Useful to know the movement of an entity as a part in a game of chess

  • 0 : passable
  • 1 : not passable

Before, Insert the script pathfinding-browser.js in header

Attention ! The matrix is different that matrix of the library. The columns are the rows and rows are the columns.

Returns the columns and rows of path. If no arguments, returns the PF.Grid. You can use the API library.

var matrix = [
    [0, 0, 0, 1, 0],
    [1, 0, 0, 0, 1],
    [0, 0, 1, 0, 0],
];
var grid = Class.New("Grid", [matrix]);
var pf_grid = grid.pathfinding();
pf_grid.setWalkableAt(1, 2, false);

Usage

Parameters

  • row0 {Integer}

    Start position (row)

  • col0 {Integer}

    Start position (col)

  • row1 {Integer}

    Final position (row)

  • col1 {Integer}

    Final position (col)

  • type {String} optional

    (optional) Type of the search algorithm

    • AStarFinder (default)
    • BreadthFirstFinder
    • BestFirstFinder
    • DijkstraFinder
    • BiAStarFinder
    • BiBestFirstFinder
    • BiDijkstraFinder
    • BiBreadthFirstFinder
    • JumpPointFinder

  • options {Object} optional

    (optional) Library Options. See https://github.com/qiao/PathFinding.js

Returns

Array|PF.Grid

Example

In ready method

var matrix = [
    [0, 0, 0, 1, 0],
    [1, 0, 0, 0, 1],
    [0, 0, 1, 0, 0],
];

var grid = Class.New("Grid", [matrix]);
grid.pathfinding(0, 0, 2, 4);

// returns : [[0, 0], [1, 0], [2, 0], [2, 1], [2, 2], [2, 3], [2, 4]]

grid.setPropertyByCell(0, 1, 1);
grid.pathfinding(0, 0, 2, 4);

// returns [];

Discussion