These docs are for an outdated version of Phaser The documentation on this page is for Phaser 2.6.2. The latest release is 2.9.3.

Constructor

Phaser. Weapon

new Weapon(game, parent)

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

Weapons fire Phaser.Bullet objects, which are essentially Sprites with a few extra properties.
The Bullets are enabled for Arcade Physics. They do not currently work with P2 Physics.

The Bullets are created inside of Weapon.bullets, which is a Phaser.Group instance. Anything you
can usually do with a Group, such as move it around the display list, iterate it, etc can be done
to the bullets Group too.

Bullets can have textures and even animations. You can control the speed at which they are fired,
the firing rate, the firing angle, and even set things like gravity for them.

A small example, assumed to be running from within a Phaser.State create method.

var weapon = this.add.weapon(10, 'bullet');
weapon.fireFrom.set(300, 300);
this.input.onDown.add(weapon.fire, this);

Parameters
Name Type Description
game Phaser.Game

A reference to the current Phaser.Game instance.

parent Phaser.PluginManager

The Phaser Plugin Manager which looks after this plugin.

Source code: plugins/weapon/WeaponPlugin.js (Line 31)

Public Properties

[static] KILL_CAMERA_BOUNDS : integer

A bulletKillType constant that automatically kills the bullets when they leave the Camera.bounds rectangle.

Source code: plugins/weapon/WeaponPlugin.js (Line 417)

[static] KILL_DISTANCE : integer

A bulletKillType constant that automatically kills the bullets after they
exceed the bulletDistance from their original firing position.

Source code: plugins/weapon/WeaponPlugin.js (Line 403)

[static] KILL_LIFESPAN : integer

A bulletKillType constant that automatically kills the bullets when their bulletLifespan expires.

Source code: plugins/weapon/WeaponPlugin.js (Line 395)

[static] KILL_NEVER : integer

A bulletKillType constant that stops the bullets from ever being destroyed automatically.

Source code: plugins/weapon/WeaponPlugin.js (Line 388)

[static] KILL_STATIC_BOUNDS : integer

A bulletKillType constant that automatically kills the bullets when they leave the Weapon.bounds rectangle.

Source code: plugins/weapon/WeaponPlugin.js (Line 431)

[static] KILL_WEAPON_BOUNDS : integer

A bulletKillType constant that automatically kills the bullets when they leave the Weapon.bounds rectangle.

Source code: plugins/weapon/WeaponPlugin.js (Line 410)

[static] KILL_WORLD_BOUNDS : integer

A bulletKillType constant that automatically kills the bullets when they leave the World.bounds rectangle.

Source code: plugins/weapon/WeaponPlugin.js (Line 424)

autoExpandBulletsGroup : boolean

Should the bullet pool run out of bullets (i.e. they are all in flight) then this
boolean controls if the Group will create a brand new bullet object or not.

Source code: plugins/weapon/WeaponPlugin.js (Line 46)

autofire : boolean

Will this weapon auto fire? If set to true then a new bullet will be fired
based on the fireRate value.

Source code: plugins/weapon/WeaponPlugin.js (Line 53)

bounds : Phaser.Rectangle

This Rectangle defines the bounds that are used when determining if a Bullet should be killed or not.
It's used in combination with Weapon.bulletKillType when that is set to either Phaser.Weapon.KILL_WEAPON_BOUNDS
or Phaser.Weapon.KILL_STATIC_BOUNDS. If you are not using either of these kill types then the bounds are ignored.
If you are tracking a Sprite or Point then the bounds are centered on that object every frame.

Source code: plugins/weapon/WeaponPlugin.js (Line 266)

bulletAngleOffset : number

An optional angle offset applied to the Bullets when they are launched.
This is useful if for example your bullet sprites have been drawn facing up, instead of
to the right, and you want to fire them at an angle. In which case you can set the
angle offset to be 90 and they'll be properly rotated when fired.

Source code: plugins/weapon/WeaponPlugin.js (Line 153)

bulletAngleVariance : number

This is a variance added to the angle of Bullets when they are fired.
If you fire from an angle of 90 and have a bulletAngleVariance of 20 then the actual
angle of the Bullets will be between 70 and 110 degrees. This is a quick way to add a
great 'spread' effect to a Weapon.

Source code: plugins/weapon/WeaponPlugin.js (Line 162)

bulletAnimation : string

The string based name of the animation that the Bullet will be given on launch.
This is set via Weapon.addBulletAnimation.

Source code: plugins/weapon/WeaponPlugin.js (Line 112)

bulletClass : Object

The Class of the bullets that are launched by this Weapon. Defaults Phaser.Bullet, but can be
overridden before calling createBullets and set to your own class type.

Source code: plugins/weapon/WeaponPlugin.js (Line 1111)

bulletCollideWorldBounds : boolean

Should bullets collide with the World bounds or not?

Source code: plugins/weapon/WeaponPlugin.js (Line 1199)

bulletFrame : string | integer

The Texture Frame that the Bullets use when rendering.
Changing this has no effect on bullets in-flight, only on newly spawned bullets.

Type
  • string | integer
Source code: plugins/weapon/WeaponPlugin.js (Line 221)

bulletFrameCycle : boolean

If you've added a set of frames via Weapon.setBulletFrames then you can optionally
chose for each Bullet fired to use the next frame in the set. The frame index is then
advanced one frame until it reaches the end of the set, then it starts from the start
again. Cycling frames like this allows you to create varied bullet effects via
sprite sheets.

Source code: plugins/weapon/WeaponPlugin.js (Line 129)

bulletFrameRandom : boolean

If you've added a set of frames via Weapon.setBulletFrames then you can optionally
chose for each Bullet fired to pick a random frame from the set.

Source code: plugins/weapon/WeaponPlugin.js (Line 119)

<internal> bulletFrames : Array

This array stores the frames added via Weapon.setBulletFrames.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: plugins/weapon/WeaponPlugin.js (Line 282)

bulletGravity : Phaser.Point

This is the amount of gravity added to the Bullets physics body when fired.
Gravity is expressed in pixels / second / second.

Source code: plugins/weapon/WeaponPlugin.js (Line 199)

bulletInheritSpriteSpeed : boolean

When a Bullet is fired it can optionally inherit the velocity of the trackedSprite if set.

Source code: plugins/weapon/WeaponPlugin.js (Line 105)

bulletKey : string

The Texture Key that the Bullets use when rendering.
Changing this has no effect on bullets in-flight, only on newly spawned bullets.

Source code: plugins/weapon/WeaponPlugin.js (Line 214)

bulletKillDistance : number

If you've set bulletKillType to Phaser.Weapon.KILL_DISTANCE this controls the distance
the Bullet can travel before it is automatically killed. The distance is given in pixels.

Source code: plugins/weapon/WeaponPlugin.js (Line 192)

bulletKillType : integer

This controls how the bullets will be killed. The default is Phaser.Weapon.KILL_WORLD_BOUNDS.

There are 7 different "kill types" available:

  • Phaser.Weapon.KILL_NEVER
    The bullets are never destroyed by the Weapon. It's up to you to destroy them via your own code.

  • Phaser.Weapon.KILL_LIFESPAN
    The bullets are automatically killed when their bulletLifespan amount expires.

  • Phaser.Weapon.KILL_DISTANCE
    The bullets are automatically killed when they exceed bulletDistance pixels away from their original launch position.

  • Phaser.Weapon.KILL_WEAPON_BOUNDS
    The bullets are automatically killed when they no longer intersect with the Weapon.bounds rectangle.

  • Phaser.Weapon.KILL_CAMERA_BOUNDS
    The bullets are automatically killed when they no longer intersect with the Camera.bounds rectangle.

  • Phaser.Weapon.KILL_WORLD_BOUNDS
    The bullets are automatically killed when they no longer intersect with the World.bounds rectangle.

  • Phaser.Weapon.KILL_STATIC_BOUNDS
    The bullets are automatically killed when they no longer intersect with the Weapon.bounds rectangle.
    The difference between static bounds and weapon bounds, is that a static bounds will never be adjusted to
    match the position of a tracked sprite or pointer.

Source code: plugins/weapon/WeaponPlugin.js (Line 1136)

bulletLifespan : number

If you've set bulletKillType to Phaser.Weapon.KILL_LIFESPAN this controls the amount
of lifespan the Bullets have set on launch. The value is given in milliseconds.
When a Bullet hits its lifespan limit it will be automatically killed.

Source code: plugins/weapon/WeaponPlugin.js (Line 185)

bulletRotateToVelocity : boolean

Bullets can optionally adjust their rotation in-flight to match their velocity.
This can create the effect of a bullet 'pointing' to the path it is following, for example
an arrow being fired from a bow, and works especially well when added to bulletGravity.

Source code: plugins/weapon/WeaponPlugin.js (Line 207)

bullets : Phaser.Group

This is the Phaser.Group that contains all of the bullets managed by this plugin.

Source code: plugins/weapon/WeaponPlugin.js (Line 39)

bulletSpeed : number

The speed at which the bullets are fired. This value is given in pixels per second, and
is used to set the starting velocity of the bullets.

Source code: plugins/weapon/WeaponPlugin.js (Line 169)

bulletSpeedVariance : number

This is a variance added to the speed of Bullets when they are fired.
If bullets have a bulletSpeed value of 200, and a bulletSpeedVariance of 50
then the actual speed of the Bullets will be between 150 and 250 pixels per second.

Source code: plugins/weapon/WeaponPlugin.js (Line 177)

bulletWorldWrap : boolean

Should the Bullets wrap around the world bounds? This automatically calls
World.wrap on the Bullet each frame. See the docs for that method for details.

Source code: plugins/weapon/WeaponPlugin.js (Line 136)

bulletWorldWrapPadding : integer

If bulletWorldWrap is true then you can provide an optional padding value with this
property. It's added to the calculations determining when the Bullet should wrap around
the world or not. The value is given in pixels.

Source code: plugins/weapon/WeaponPlugin.js (Line 144)

fireAngle : integer

The angle at which the bullets are fired. This can be a const such as Phaser.ANGLE_UP
or it can be any number from 0 to 360 inclusive, where 0 degrees is to the right.

Source code: plugins/weapon/WeaponPlugin.js (Line 99)

fireFrom : Phaser.Rectangle

This is a Rectangle from within which the bullets are fired. By default it's a 1x1
rectangle, the equivalent of a Point. But you can change the width and height, and if
larger than 1x1 it'll pick a random point within the rectangle to launch the bullet from.

Source code: plugins/weapon/WeaponPlugin.js (Line 92)

fireLimit : number

The maximum number of shots that this Weapon is allowed to fire before it stops.
When the limit is his the Weapon.onFireLimit Signal is dispatched.
You can reset the shot counter via Weapon.resetShots.

Source code: plugins/weapon/WeaponPlugin.js (Line 69)

fireRate : number

The rate at which this Weapon can fire. The value is given in milliseconds.

Source code: plugins/weapon/WeaponPlugin.js (Line 75)

fireRateVariance : number

This is a modifier that is added to the fireRate each update to add variety
to the firing rate of the Weapon. The value is given in milliseconds.
If you've a fireRate of 200 and a fireRateVariance of 50 then the actual
firing rate of the Weapon will be between 150 and 250.

Source code: plugins/weapon/WeaponPlugin.js (Line 84)

onFire : Phaser.Signal

The onFire Signal is dispatched each time Weapon.fire is called, and a Bullet is
successfully launched. The callback is set two arguments: a reference to the bullet sprite itself,
and a reference to the Weapon that fired the bullet.

Source code: plugins/weapon/WeaponPlugin.js (Line 306)

onFireLimit : Phaser.Signal

The onFireLimit Signal is dispatched if Weapon.fireLimit is > 0, and a bullet launch takes the number
of shots fired to equal the fire limit.
The callback is sent two arguments: A reference to the Weapon that hit the limit, and the value of
Weapon.fireLimit.

Source code: plugins/weapon/WeaponPlugin.js (Line 325)

onKill : Phaser.Signal

The onKill Signal is dispatched each time a Bullet that is in-flight is killed. This can be the result
of leaving the Weapon bounds, an expiring lifespan, or exceeding a specified distance.
The callback is sent one argument: A reference to the bullet sprite itself.

Source code: plugins/weapon/WeaponPlugin.js (Line 315)

shots : number

The total number of bullets this Weapon has fired so far.
You can limit the number of shots allowed (via fireLimit), and reset
this total via Weapon.resetShots.

Source code: plugins/weapon/WeaponPlugin.js (Line 61)

trackedPointer : Phaser.Pointer

The Pointer currently being tracked by the Weapon, if any.
This is set via the Weapon.trackPointer method.

Source code: plugins/weapon/WeaponPlugin.js (Line 341)

trackedSprite : Phaser.Sprite | Object

The Sprite currently being tracked by the Weapon, if any.
This is set via the Weapon.trackSprite method.

Type
Source code: plugins/weapon/WeaponPlugin.js (Line 333)

trackOffset : Phaser.Point

The Track Offset is a Point object that allows you to specify a pixel offset that bullets use
when launching from a tracked Sprite or Pointer. For example if you've got a bullet that is 2x2 pixels
in size, but you're tracking a Sprite that is 32x32, then you can set trackOffset.x = 16 to have
the bullet launched from the center of the Sprite.

Source code: plugins/weapon/WeaponPlugin.js (Line 360)

trackRotation : boolean

If the Weapon is tracking a Sprite, should it also track the Sprites rotation?
This is useful for a game such as Asteroids, where you want the weapon to fire based
on the sprites rotation.

Source code: plugins/weapon/WeaponPlugin.js (Line 350)

x : number

The x coordinate from which bullets are fired. This is the same as Weapon.fireFrom.x, and
can be overridden by the Weapon.fire arguments.

Source code: plugins/weapon/WeaponPlugin.js (Line 1224)

y : number

The y coordinate from which bullets are fired. This is the same as Weapon.fireFrom.y, and
can be overridden by the Weapon.fire arguments.

Source code: plugins/weapon/WeaponPlugin.js (Line 1246)

Public Methods

addBulletAnimation(name, frames, frameRate, loop, useNumericIndex) → {Phaser.Weapon}

Adds a new animation under the given key. Optionally set the frames, frame rate and loop.
The arguments are all the same as for Animation.add, and work in the same way.

Weapon.bulletAnimation will be set to this animation after it's created. From that point on, all
bullets fired will play using this animation. You can swap between animations by calling this method
several times, and then just changing the Weapon.bulletAnimation property to the name of the animation
you wish to play for the next launched bullet.

If you wish to stop using animations at all, set Weapon.bulletAnimation to '' (an empty string).

Parameters
Name Type Argument Default Description
name string

The unique (within the Weapon instance) name for the animation, i.e. "fire", "blast".

frames Array <optional>
null

An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used.

frameRate number <optional>
60

The speed at which the animation should play. The speed is given in frames per second.

loop boolean <optional>
false

Whether or not the animation is looped or just plays once.

useNumericIndex boolean <optional>
true

Are the given frames using numeric indexes (default) or strings?

Returns

The Weapon Plugin.

Source code: plugins/weapon/WeaponPlugin.js (Line 1048)

createBullets(quantity, key, frame, group) → {Phaser.Weapon}

This method performs two actions: First it will check to see if the Weapon.bullets Group exists or not,
and if not it creates it, adding it the group given as the 4th argument.

Then it will seed the bullet pool with the quantity number of Bullets, using the texture key and frame
provided (if any).

If for example you set the quantity to be 10, then this Weapon will only ever be able to have 10 bullets
in-flight simultaneously. If you try to fire an 11th bullet then nothing will happen until one, or more, of
the in-flight bullets have been killed, freeing them up for use by the Weapon again.

If you do not wish to have a limit set, then pass in -1 as the quantity. In this instance the Weapon will
keep increasing the size of the bullet pool as needed. It will never reduce the size of the pool however,
so be careful it doesn't grow too large.

You can either set the texture key and frame here, or via the Weapon.bulletKey and Weapon.bulletFrame
properties. You can also animate bullets, or set them to use random frames. All Bullets belonging to a
single Weapon instance must share the same texture key however.

Parameters
Name Type Argument Default Description
quantity integer <optional>
1

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

key string <optional>

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

frame integer | string <optional>

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

group Phaser.Group <optional>

Optional Group to add the object to. If not specified it will be added to the World group.

Returns

This Weapon instance.

Source code: plugins/weapon/WeaponPlugin.js (Line 433)

debug(x, y, debugBodies)

Uses Game.Debug to draw some useful information about this Weapon, including the number of bullets
both in-flight, and available. And optionally the physics debug bodies of the bullets.

Parameters
Name Type Argument Default Description
x integer <optional>
16

The coordinate, in screen space, at which to draw the Weapon debug data.

y integer <optional>
32

The coordinate, in screen space, at which to draw the Weapon debug data.

debugBodies boolean <optional>
false

Optionally draw the physics body of every bullet in-flight.

Source code: plugins/weapon/WeaponPlugin.js (Line 1086)

destroy()

Destroys this Weapon. It removes itself from the PluginManager, destroys
the bullets Group, and nulls internal references.

Source code: plugins/weapon/WeaponPlugin.js (Line 579)

fire(from, x, y) → {Phaser.Bullet}

Attempts to fire a single Bullet. If there are no more bullets available in the pool, and the pool cannot be extended,
then this method returns false. It will also return false if not enough time has expired since the last time
the Weapon was fired, as defined in the Weapon.fireRate property.

Otherwise the first available bullet is selected and launched.

The arguments are all optional, but allow you to control both where the bullet is launched from, and aimed at.

If you don't provide any of the arguments then it uses those set via properties such as Weapon.trackedSprite,
Weapon.bulletAngle and so on.

When the bullet is launched it has its texture and frame updated, as required. The velocity of the bullet is
calculated based on Weapon properties like bulletSpeed.

Parameters
Name Type Argument Description
from Phaser.Sprite | Phaser.Point | Object <optional>

Optionally fires the bullet from the x and y properties of this object. If set this overrides Weapon.trackedSprite or trackedPointer. Pass null to ignore it.

x number <optional>

The x coordinate, in world space, to fire the bullet towards. If left as undefined the bullet direction is based on its angle.

y number <optional>

The y coordinate, in world space, to fire the bullet towards. If left as undefined the bullet direction is based on its angle.

Returns

The fired bullet if successful, null otherwise.

Source code: plugins/weapon/WeaponPlugin.js (Line 691)

fireAtPointer(pointer) → {Phaser.Bullet}

Fires a bullet at the given Pointer. The bullet will be launched from the Weapon.fireFrom position,
or from a Tracked Sprite or Pointer, if you have one set.

Parameters
Name Type Argument Description
pointer Phaser.Pointer <optional>

The Pointer to fire the bullet towards.

Returns

The fired bullet if successful, null otherwise.

Source code: plugins/weapon/WeaponPlugin.js (Line 928)

fireAtSprite(sprite) → {Phaser.Bullet}

Fires a bullet at the given Sprite. The bullet will be launched from the Weapon.fireFrom position,
or from a Tracked Sprite or Pointer, if you have one set.

Parameters
Name Type Argument Description
sprite Phaser.Sprite <optional>

The Sprite to fire the bullet towards.

Returns

The fired bullet if successful, null otherwise.

Source code: plugins/weapon/WeaponPlugin.js (Line 944)

fireAtXY(x, y) → {Phaser.Bullet}

Fires a bullet at the given coordinates. The bullet will be launched from the Weapon.fireFrom position,
or from a Tracked Sprite or Pointer, if you have one set.

Parameters
Name Type Argument Description
x number <optional>

The x coordinate, in world space, to fire the bullet towards.

y number <optional>

The y coordinate, in world space, to fire the bullet towards.

Returns

The fired bullet if successful, null otherwise.

Source code: plugins/weapon/WeaponPlugin.js (Line 958)

forEach(callback, callbackContext, args) → {Phaser.Weapon}

Call a function on each in-flight bullet in this Weapon.

See forEachExists for more details.

Parameters
Name Type Argument Default Description
callback function

The function that will be called for each applicable child. The child will be passed as the first argument.

callbackContext object

The context in which the function should be called (usually 'this').

args any <optional>
<repeatable>
(none)

Additional arguments to pass to the callback function, after the child item.

Returns

This Weapon instance.

Source code: plugins/weapon/WeaponPlugin.js (Line 490)

killAll() → {Phaser.Weapon}

Calls Bullet.kill on every in-flight bullet in this Weapon.
Also re-enables their physics bodies, should they have been disabled via pauseAll.

Returns

This Weapon instance.

Source code: plugins/weapon/WeaponPlugin.js (Line 541)

pauseAll() → {Phaser.Weapon}

Sets Body.enable to false on each bullet in this Weapon.
This has the effect of stopping them in-flight should they be moving.
It also stops them being able to be checked for collision.

Returns

This Weapon instance.

Source code: plugins/weapon/WeaponPlugin.js (Line 509)

resetShots(newLimit) → {Phaser.Weapon}

Resets the Weapon.shots counter back to zero. This is used when you've set
Weapon.fireLimit, and have hit (or just wish to reset) your limit.

Parameters
Name Type Argument Description
newLimit integer <optional>

Optionally set a new Weapon.fireLimit.

Returns

This Weapon instance.

Source code: plugins/weapon/WeaponPlugin.js (Line 558)

resumeAll() → {Phaser.Weapon}

Sets Body.enable to true on each bullet in this Weapon.
This has the effect of resuming their motion should they be in-flight.
It also enables them for collision checks again.

Returns

This Weapon instance.

Source code: plugins/weapon/WeaponPlugin.js (Line 525)

setBulletBodyOffset(width, height, offsetX, offsetY) → {Phaser.Weapon}

You can modify the size of the physics Body the Bullets use to be any dimension you need.
This allows you to make it smaller, or larger, than the parent Sprite.
You can also control the x and y offset of the Body. This is the position of the
Body relative to the top-left of the Sprite texture.

For example: If you have a Sprite with a texture that is 80x100 in size,
and you want the physics body to be 32x32 pixels in the middle of the texture, you would do:

setSize(32, 32, 24, 34)

Where the first two parameters is the new Body size (32x32 pixels).
24 is the horizontal offset of the Body from the top-left of the Sprites texture, and 34
is the vertical offset.

Parameters
Name Type Argument Description
width number

The width of the Body.

height number

The height of the Body.

offsetX number <optional>

The X offset of the Body from the top-left of the Sprites texture.

offsetY number <optional>

The Y offset of the Body from the top-left of the Sprites texture.

Returns

The Weapon Plugin.

Source code: plugins/weapon/WeaponPlugin.js (Line 973)

setBulletFrames(min, max, cycle, random) → {Phaser.Weapon}

Sets the texture frames that the bullets can use when being launched.

This is intended for use when you've got numeric based frames, such as those loaded via a Sprite Sheet.

It works by calling Phaser.ArrayUtils.numberArray internally, using the min and max values
provided. Then it sets the frame index to be zero.

You can optionally set the cycle and random booleans, to allow bullets to cycle through the frames
when they're fired, or pick one at random.

Parameters
Name Type Argument Default Description
min integer

The minimum value the frame can be. Usually zero.

max integer

The maximum value the frame can be.

cycle boolean <optional>
true

Should the bullet frames cycle as they are fired?

random boolean <optional>
false

Should the bullet frames be picked at random as they are fired?

Returns

The Weapon Plugin.

Source code: plugins/weapon/WeaponPlugin.js (Line 1014)

trackPointer(pointer, offsetX, offsetY) → {Phaser.Weapon}

Sets this Weapon to track the given Pointer.
When a Weapon tracks a Pointer it will automatically update its fireFrom value to match the Pointers
position within the Game World, adjusting the coordinates based on the offset arguments.

This allows you to lock a Weapon to a Pointer, so that bullets are always launched from its location.

Calling trackPointer will reset Weapon.trackedSprite to null, should it have been set, as you can
only track either a Pointer, or a Sprite, at once, but not both.

Parameters
Name Type Argument Default Description
pointer Phaser.Pointer <optional>

The Pointer to track the position of. Defaults to Input.activePointer if not specified.

offsetX integer <optional>
0

The horizontal offset from the Pointers position to be applied to the Weapon.

offsetY integer <optional>
0

The vertical offset from the Pointers position to be applied to the Weapon.

Returns

This Weapon instance.

Source code: plugins/weapon/WeaponPlugin.js (Line 659)

trackSprite(sprite, offsetX, offsetY, trackRotation) → {Phaser.Weapon}

Sets this Weapon to track the given Sprite, or any Object with a public world Point object.
When a Weapon tracks a Sprite it will automatically update its fireFrom value to match the Sprites
position within the Game World, adjusting the coordinates based on the offset arguments.

This allows you to lock a Weapon to a Sprite, so that bullets are always launched from its location.

Calling trackSprite will reset Weapon.trackedPointer to null, should it have been set, as you can
only track either a Sprite, or a Pointer, at once, but not both.

Parameters
Name Type Argument Default Description
sprite Phaser.Sprite | Object

The Sprite to track the position of.

offsetX integer <optional>
0

The horizontal offset from the Sprites position to be applied to the Weapon.

offsetY integer <optional>
0

The vertical offset from the Sprites position to be applied to the Weapon.

trackRotation boolean <optional>
false

Should the Weapon also track the Sprites rotation?

Returns

This Weapon instance.

Source code: plugins/weapon/WeaponPlugin.js (Line 626)

<internal> update()

Internal update method, called by the PluginManager.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: plugins/weapon/WeaponPlugin.js (Line 598)