Weapon#createBullets()

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)
doc_phaser
2017-02-14 11:19:48
Comments
Leave a Comment

Please login to continue.