Weapon#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)
doc_phaser
2017-02-14 11:20:02
Comments
Leave a Comment

Please login to continue.