melonJS
    Preparing search index...

    Class PathfindingPlugin

    Keeps a pathfinding Grid for the current level: built when a level is loaded, from a tile layer or from the level's collision shapes, and replaced by the next level's.

    It is only a convenience for games whose grid comes from the level: a Grid works on its own.

    import { plugin } from "melonjs";
    import { PathfindingPlugin } from "@melonjs/pathfinding-plugin";

    plugin.register(PathfindingPlugin, "pathfinding", { layer: "walls" });
    // once a level is loaded
    const pathfinding = plugin.cache.pathfinding;
    const { path } = pathfinding.grid.findPath(enemy.pos, player.pos);

    Hierarchy (View Summary)

    Index

    a reference to the app/game that registered this plugin

    grid: Grid | null = null

    the current level's grid, or null before a level is loaded

    version: string

    define the minimum required version of melonJS this can be overridden by the plugin

    • build the grid of the current level again: after the map changed in a way the grid did not see

      Returns Grid | null

      the new grid, or null with no level, no such layer, or a build that returned null. Built from the collision shapes, it covers the whole level: on an infinite map, from its first painted column and row, which can be left of or above the map's origin.

      on a staggered or hexagonal map, or a subdivide that is not a whole number of 1 or more (on a level load, a warning instead, and no grid)