phaser-navmesh
Version:
A plugin for Phaser (v3) for fast pathfinding using navigation meshes
90 lines • 4.42 kB
TypeScript
/// <reference types="navmesh/src/javascript-astar" />
import { Point, PolyPoints } from "navmesh/src";
import Phaser from "phaser";
import PhaserNavMeshPlugin from "./phaser-navmesh-plugin";
/**
* A wrapper around {@link NavMesh} for Phaser 3. Create instances of this class from
* {@link PhaserNavMeshPlugin}. This is the workhorse that represents a navigation mesh built from a
* series of polygons. Once built, the mesh can be asked for a path from one point to another point.
*
* Compared to {@link NavMesh}, this adds visual debugging capabilities and converts paths to
* Phaser-compatible point instances.
*
* @export
* @class PhaserNavMesh
*/
export default class PhaserNavMesh {
private key;
private plugin;
private scene;
private debugGraphics;
private navMesh;
/**
* Creates an instance of PhaserNavMesh.
* @param plugin The plugin that owns this mesh.
* @param scene
* @param key The key the mesh is stored under within the plugin.
* @param meshPolygonPoints Array where each element is an array of point-like objects that
* defines a polygon.
* @param meshShrinkAmount The amount (in pixels) that the navmesh has been shrunk around
* obstacles (a.k.a the amount obstacles have been expanded)
*/
constructor(plugin: PhaserNavMeshPlugin, scene: Phaser.Scene, key: string, meshPolygonPoints: PolyPoints[], meshShrinkAmount?: number);
/**
* Find if the given point is within any of the polygons in the mesh.
* @param point
*/
isPointInMesh(point: Point): boolean;
/**
* See {@link NavMesh#findPath}. This implements the same functionality, except that the returned
* path is converted to Phaser-compatible points.
* @param startPoint A point-like object
* @param endPoint A point-like object
* @param PointClass The class used to represent points in the final path
* @returns An array of points if a path is found, or null if no path
*/
findPath(startPoint: Point, endPoint: Point, PointClass?: typeof Phaser.Geom.Point): Phaser.Geom.Point[] | null;
/**
* Enable the debug drawing graphics. If no graphics object is provided, a new instance will be
* created.
* @param graphics An optional graphics object for the mesh to use for debug drawing. Note, the
* mesh will destroy this graphics object when the mesh is destroyed.
* @returns The graphics object this mesh uses.
*/
enableDebug(graphics: Phaser.GameObjects.Graphics): Phaser.GameObjects.Graphics | null;
/** Hide the debug graphics, but don't destroy it. */
disableDebug(): void;
/** Returns true if the debug graphics object is enabled and visible. */
isDebugEnabled(): boolean | null;
/** Clear the debug graphics. */
debugDrawClear(): void;
/**
* Visualize the polygons in the navmesh by drawing them to the debug graphics.
* @param options
* @param [options.drawCentroid=true] For each polygon, show the approx centroid
* @param [options.drawBounds=false] For each polygon, show the bounding radius
* @param [options.drawNeighbors=true] For each polygon, show the connections to neighbors
* @param [options.drawPortals=true] For each polygon, show the portal edges
* @param [options.palette=[0x00a0b0, 0x6a4a3c, 0xcc333f, 0xeb6841, 0xedc951]] An array of
* Phaser-compatible format colors to use when drawing the individual polygons. The first poly
* uses the first color, the second poly uses the second color, etc.
*/
debugDrawMesh({ drawCentroid, drawBounds, drawNeighbors, drawPortals, palette, }?: {
drawCentroid?: boolean | undefined;
drawBounds?: boolean | undefined;
drawNeighbors?: boolean | undefined;
drawPortals?: boolean | undefined;
palette?: number[] | undefined;
}): void;
/**
* Visualize a path (array of points) on the debug graphics.
* @param path Array of point-like objects in the form {x, y}
* @param color
* @param thickness
* @param alpha
*/
debugDrawPath(path: Point[], color?: number, thickness?: number, alpha?: number): void;
/** Destroy the mesh, kill the debug graphic and unregister itself with the plugin. */
destroy(): void;
}
//# sourceMappingURL=phaser-navmesh.d.ts.map