Skip to Content
defold-typescript libraries
s-kania

s-kania/def-windward-jps/def_windward_jps

Find paths on 2D grids with Jump Point Search.

  • GitHub: s-kania/def-windward-jps — pinned to v1.1.0
    1. Pick a release from s-kania/def-windward-jps releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as def_windward_jps from "def_windward_jps"

Functions

create_grid(width: number, height: number, walls: Point[]): Grid

Creates a grid to find paths on.

Parameters

  • width: number — Number of cells horizontally.
  • height: number — Number of cells vertically.
  • walls: Point[] — Blocked cells, such as [[10, 12], [11, 12]]. ⚠️ 1-based; passed to def_windward_jps unchanged.

Returns

  • Grid — The new grid.

Types

type Point = [ x: number, y: number ]

type Heuristic = "octile" | "manhattan" | "euclidean"

Grid

Grid.find_path(start: Point, goal: Point, heuristic?: Heuristic): LuaMultiReturn<[ Point[], undefined ] | [ undefined, string ]>

Finds a path between two cells. A start or goal that is outside the grid or blocked, or a goal that cannot be reached, fails with an error message instead of a path, so check path before reading it.

Parameters

  • start: Point — Cell to start from. ⚠️ 1-based; passed to def_windward_jps unchanged.
  • goal: Point — Cell to reach. ⚠️ 1-based; passed to def_windward_jps unchanged.
  • heuristic?: Heuristic — Distance estimate to search with. Default is "octile".

Returns

  • LuaMultiReturn<[ Point[], undefined ] | [ undefined, string ]> — path, the cells from start to goal, and nil; or nil and message, why the search failed. ⚠️ path is 1-based; passed to def_windward_jps unchanged.

Grid.is_walkable(point: Point): boolean

Whether a cell is inside the grid and not blocked. Use it to check a cell before searching from or to it.

Parameters

  • point: Point — Cell to check. ⚠️ 1-based; passed to def_windward_jps unchanged.

Returns

  • boolean — true if the cell can be walked through.

On this page