Options
All
  • Public
  • Public/Protected
  • All
Menu

The Weapon Plugin provides the ability to easily create a Weapon with its own bullet pool and manager.

see

Weapon for a more detailed explanation.

example

A small example on how to install the plugin, assumed to be running from within a Phaser.Scene.create method:

// Install it into a scene
this.plugins.installScenePlugin(
'WeaponPlugin',
WeaponPlugin,
'weapons',
this
);

Hierarchy

Index

Constructors

constructor

Properties

Protected game

game: Game

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

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.

weapons

weapons: Weapon[]

Methods

add

  • add(bulletLimit?: number, key?: string, frame?: string, group?: Group, weaponClass?: typeof Weapon): Weapon
  • Parameters

    • Optional bulletLimit: number

      The quantity of bullets to seed the Weapon with. If -1 it will set the pool to automatically expand.

    • Optional key: string

      The Game.cache key of the image that this Sprite will use.

    • Optional frame: string

      If the Sprite image contains multiple frames you can specify which one to use here.

    • Optional group: Group

      Optional Group to add the object to.

    • weaponClass: typeof Weapon = ...

      Optional custom class for the Weapon.

    Returns Weapon

    The weapon that was created

boot

  • boot(): void
  • If this is a Scene Plugin (i.e. installed into a Scene) then this method is called when the Scene boots. By this point the plugin properties scene and systems will have already been set. In here you can listen for Scene events and set-up whatever you need for this plugin to run.

    Returns void

destroy

  • destroy(): void
  • Destroys this Weapon. You must release everything in here, all references, all objects, free it all up.

    Returns void

init

  • init(data?: any): void
  • The PluginManager calls this method on a Global Plugin when the plugin is first instantiated. It will never be called again on this instance. In here you can set-up whatever you need for this plugin to run. If a plugin is set to automatically start then BasePlugin.start will be called immediately after this. On a Scene Plugin, this method is never called. Use {@link Phaser.Plugins.ScenePlugin#boot} instead.

    Parameters

    • Optional data: any

      A value specified by the user, if any, from the data property of the plugin's configuration object (if started at game boot) or passed in the PluginManager's install method (if started manually).

    Returns void

Protected postRender

  • postRender(): void

start

  • start(): void
  • Called by the PluginManager when this plugin is started. If a plugin is stopped, and then started again, this will get called again. Typically called immediately after BasePlugin.init.

    Returns 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

Protected update

  • update(): void

Generated using TypeDoc