A reference to the current Phaser.Game instance.
The Phaser Plugin Manager which looks after this plugin.
Adds a new animation under the given key.
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).
The unique (within the Weapon instance) name for the animation, i.e. "fire", "blast".
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.
The speed at which the animation should play. The speed is given in frames per second.
Whether or not the animation is looped or just plays once.
Are the given frames using numeric indexes (default) or strings?
The Weapon Plugin.
Should the bullet pool run out of bullets (i.e.
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.
Will this weapon auto fire? If set to true then a new bullet will be fired based on the fireRate
value.
This Rectangle defines the bounds that are used when determining if a Bullet should be killed or not.
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.
The string based name of the animation that the Bullet will be given on launch.
The string based name of the animation that the Bullet will be given on launch. This is set via Weapon.addBulletAnimation.
The Class of the bullets that are launched by this Weapon.
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.
Should bullets collide with the World bounds or not?
The Texture Frame that the Bullets use when rendering.
The Texture Frame that the Bullets use when rendering. Changing this has no effect on bullets in-flight, only on newly spawned bullets.
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.
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.
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.
This is the amount of gravity added to the Bullets physics body when fired.
This is the amount of gravity added to the Bullets physics body when fired. Gravity is expressed in pixels / second / second.
When a Bullet is fired it can optionally inherit the velocity of the trackedSprite
if set.
If you've set bulletKillType
to Phaser.Weapon.KILL_DISTANCE this controls the distance
the Bullet can travel before it is automatically killed.
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.
If you've set bulletKillType to Phaser.Weapon.KILL_DISTANCE this controls the distance the Bullet can travel before it is automatically killed.
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.
This controls how the bullets will be killed.
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_STATIC_BOUNDS
Phaser.Weapon.KILL_WORLD_BOUNDS
Phaser.Weapon.KILL_CAMERA_BOUNDS
Phaser.Weapon.KILL_WEAPON_BOUNDS
Phaser.Weapon.KILL_DISTANCE
Phaser.Weapon.KILL_LIFESPAN
Phaser.Weapon.KILL_NEVER
If you've set bulletKillType
to Phaser.Weapon.KILL_LIFESPAN this controls the amount
of lifespan the Bullets have set on launch.
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.
Bullets can optionally adjust their rotation in-flight to match their velocity.
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
.
The speed at which the bullets are fired.
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.
This is a variance added to the speed of Bullets when they are fired.
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.
Should the Bullets wrap around the world bounds? This automatically calls
World.wrap
on the Bullet each frame.
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.
If bulletWorldWrap
is true then you can provide an optional padding value with this
property.
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.
This is the Phaser.Group that contains all of the bullets managed by this plugin.
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.
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.
The quantity of bullets to seed the Weapon with. If -1 it will set the pool to automatically expand.
The Game.cache key of the image that this Sprite will use.
If the Sprite image contains multiple frames you can specify which one to use here.
Optional Group to add the object to. If not specified it will be added to the World group.
This Weapon instance.
Uses Game.Debug to draw some useful information about this Weapon, including the number of bullets both in-flight, and available.
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.
The coordinate, in screen space, at which to draw the Weapon debug data.
The coordinate, in screen space, at which to draw the Weapon debug data.
Optionally draw the physics body of every bullet in-flight.
Destroys this Weapon.
Destroys this Weapon. It removes itself from the PluginManager, destroys the bullets Group, and nulls internal references.
The angle at which the bullets are fired.
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.
This is a Rectangle from within which the bullets are fired.
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.
he maximum number of shots that this Weapon is allowed to fire before it stops.
he 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
.
The rate at which this Weapon can fire.
The rate at which this Weapon can fire. The value is given in milliseconds.
This is a modifier that is added to the fireRate each update to add variety to the firing rate of the Weapon.
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.
A reference to the current Phaser.Game instance.
The onFire Signal is dispatched each time Weapon.fire is called, and a Bullet is successfully launched.
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.
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 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
.
The onKill Signal is dispatched each time a Bullet that is in-flight is killed.
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.
The Phaser Plugin Manager which looks after this plugin.
The total number of bullets this Weapon has fired so far.
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.
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.
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.
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.
The Pointer currently being tracked by the Weapon, if any.
The Pointer currently being tracked by the Weapon, if any. This is set via the Weapon.trackPointer method.
The Sprite currently being tracked by the Weapon, if any.
The Sprite currently being tracked by the Weapon, if any. This is set via the Weapon.trackSprite method.
The x coordinate from which bullets are fired.
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.
The y coordinate from which bullets are fired.
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.
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.
http://phaser.io/docs/2.6.2/Phaser.Weapon.html