Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • ScenePlugin
    • PhaserNavMeshPlugin

Index

Constructors

constructor

  • new PhaserNavMeshPlugin(scene: Scene, pluginManager: PluginManager, pluginKey: string): PhaserNavMeshPlugin

Properties

Protected game

game: Game

A reference to the Game instance this plugin is running under.

Private phaserNavMeshes

phaserNavMeshes: Record<string, PhaserNavMesh> = {}

Readonly pluginKey

pluginKey: string

The key under which this plugin was installed into the Scene Systems.

This property is only set when the plugin is instantiated and added to the Scene, not before. You can use it during the boot method.

Protected pluginManager

pluginManager: PluginManager

A handy reference to the Plugin Manager that is responsible for this plugin. Can be used as a route to gain access to game systems and events.

Protected scene

scene: Scene

A reference to the Scene that has installed this plugin. Only set if it's a Scene Plugin, otherwise null. This property is only set when the plugin is instantiated and added to the Scene, not before. You can use it during the boot method.

Protected systems

systems: Systems

A reference to the Scene Systems of the Scene that has installed this plugin. Only set if it's a Scene Plugin, otherwise null. This property is only set when the plugin is instantiated and added to the Scene, not before. You can use it during the boot method.

Methods

boot

  • boot(): void

buildMeshFromTiled

  • buildMeshFromTiled(key: string, objectLayer: ObjectLayer, meshShrinkAmount?: number): PhaserNavMesh
  • Load a navmesh from Tiled. Currently assumes that the polygons are squares! Does not support tilemap layer scaling, rotation or position.

    Parameters

    • key: string

      Key to use when storing this navmesh within the plugin.

    • objectLayer: ObjectLayer

      The ObjectLayer from a tilemap that contains the polygons that make up the navmesh.

    • meshShrinkAmount: number = 0

      The amount (in pixels) that the navmesh has been shrunk around obstacles (a.k.a the amount obstacles have been expanded)

    Returns PhaserNavMesh

buildMeshFromTilemap

  • buildMeshFromTilemap(key: string, tilemap: Tilemap, tilemapLayers?: TilemapLayer[], isWalkable?: (tile: Tile) => boolean, shrinkAmount?: number): PhaserNavMesh
  • 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.

    Parameters

    • key: string

      Key to use when storing this navmesh within the plugin.

    • tilemap: Tilemap

      The tilemap to use for building the navmesh.

    • Optional tilemapLayers: TilemapLayer[]

      An optional array of tilemap layers to use for building the mesh.

    • Optional isWalkable: (tile: Tile) => boolean

      An optional function to use to test if a tile is walkable. Defaults to assuming non-colliding tiles are walkable.

        • (tile: Tile): boolean
        • Parameters

          • tile: Tile

          Returns boolean

    • shrinkAmount: number = 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).

    Returns PhaserNavMesh

destroy

  • destroy(): void

init

  • init(): void

removeAllMeshes

  • removeAllMeshes(): void

removeMesh

  • removeMesh(key: string): void

start

  • start(): void

stop

  • stop(): void
  • The PluginManager calls this method on a Global Plugin when the plugin is stopped. The game code has requested that your plugin stop doing whatever it does. It is now considered as 'inactive' by the PluginManager. Handle that process here (i.e. stop listening for events, etc) If the plugin is started again then BasePlugin.start will be called again. On a Scene Plugin, this method is never called.

    Returns void

Generated using TypeDoc