phaser-navmesh
Version:
A plugin for Phaser (v3) for fast pathfinding using navigation meshes
61 lines • 3.32 kB
TypeScript
import Phaser from "phaser";
import PhaserNavMesh from "./phaser-navmesh";
/**
* This class can create navigation meshes for use in Phaser 3. The navmeshes can be constructed
* from convex polygons embedded in a Tiled map. The class that conforms to Phaser 3's plugin
* structure.
*
* @export
* @class PhaserNavMeshPlugin
*/
export default class PhaserNavMeshPlugin extends Phaser.Plugins.ScenePlugin {
private phaserNavMeshes;
constructor(scene: Phaser.Scene, pluginManager: Phaser.Plugins.PluginManager, pluginKey: string);
/** Phaser.Scene lifecycle event */
boot(): void;
/** Phaser.Scene lifecycle event - noop in this plugin, but still required. */
init(): void;
/** Phaser.Scene lifecycle event - noop in this plugin, but still required.*/
start(): void;
/** Phaser.Scene lifecycle event - will destroy all navmeshes created. */
destroy(): void;
/**
* Remove all the meshes from the navmesh.
*/
removeAllMeshes(): void;
/**
* Remove the navmesh stored under the given key from the plugin. This does not destroy the
* navmesh.
* @param key
*/
removeMesh(key: string): void;
/**
* This method attempts to automatically build a navmesh based on the give tilemap and tilemap
* layer(s). It attempts to respect the x/y position and scale of the layer(s). Important note: it
* doesn't support rotation/flip or multiple layers that have different positions/scales. This
* method is a bit experimental. It will generate a valid mesh, but it won't necessarily be
* optimal, so you may end up sometimes getting non-shortest paths.
*
* @param key Key to use when storing this navmesh within the plugin.
* @param tilemap The tilemap to use for building the navmesh.
* @param [tilemapLayers] An optional array of tilemap layers to use for building the mesh.
* @param [isWalkable] An optional function to use to test if a tile is walkable. Defaults to
* assuming non-colliding tiles are walkable.
* @param [shrinkAmount=0] Amount to "shrink" the mesh away from the tiles. This adds more
* polygons to the generated mesh, but can be helpful for preventing agents from getting caught on
* edges. This supports values between 0 and tileWidth/tileHeight (whichever dimension is
* smaller).
*/
buildMeshFromTilemap(key: string, tilemap: Phaser.Tilemaps.Tilemap, tilemapLayers?: Phaser.Tilemaps.TilemapLayer[], isWalkable?: (tile: Phaser.Tilemaps.Tile) => boolean, shrinkAmount?: number): PhaserNavMesh;
/**
* Load a navmesh from Tiled. Currently assumes that the polygons are squares! Does not support
* tilemap layer scaling, rotation or position.
* @param key Key to use when storing this navmesh within the plugin.
* @param objectLayer The ObjectLayer from a tilemap that contains the polygons that make up the
* navmesh.
* @param meshShrinkAmount The amount (in pixels) that the navmesh has been shrunk around
* obstacles (a.k.a the amount obstacles have been expanded)
*/
buildMeshFromTiled(key: string, objectLayer: Phaser.Tilemaps.ObjectLayer, meshShrinkAmount?: number): PhaserNavMesh;
}
//# sourceMappingURL=phaser-navmesh-plugin.d.ts.map