Particles.Arcade.Emitter#createMultiple()

createMultiple(quantity, key, frame, exists) → {array}

Creates multiple Phaser.Sprite objects and adds them to the top of this Group.

This method is useful if you need to quickly generate a pool of sprites, such as bullets.

Use classType to change the type of object created.

You can provide an array as the key and / or frame arguments. When you do this
it will create quantity Sprites for every key (and frame) in the arrays.

For example:

createMultiple(25, ['ball', 'carrot'])

In the above code there are 2 keys (ball and carrot) which means that 50 sprites will be
created in total, 25 of each. You can also have the frame as an array:

createMultiple(5, 'bricks', [0, 1, 2, 3])

In the above there is one key (bricks), which is a sprite sheet. The frames array tells
this method to use frames 0, 1, 2 and 3. So in total it will create 20 sprites, because
the quantity was set to 5, so that is 5 brick sprites of frame 0, 5 brick sprites with
frame 1, and so on.

If you set both the key and frame arguments to be arrays then understand it will create
a total quantity of sprites equal to the size of both arrays times each other. I.e.:

createMultiple(20, ['diamonds', 'balls'], [0, 1, 2])

The above will create 20 'diamonds' of frame 0, 20 with frame 1 and 20 with frame 2.
It will then create 20 'balls' of frame 0, 20 with frame 1 and 20 with frame 2.
In total it will have created 120 sprites.

By default the Sprites will have their exists property set to false, and they will be
positioned at 0x0, relative to the Group.x / y values.

If Group.enableBody is set, then a physics body will be created on the objects, so long as one does not already exist.

If Group.inputEnableChildren is set, then an Input Handler will be created on the objects, so long as one does not already exist.

Parameters
Name Type Argument Default Description
quantity integer

The number of Sprites to create.

key string | array

The Cache key of the image that the Sprites will use. Or an Array of keys. See the description for details on how the quantity applies when arrays are used.

frame integer | string | array <optional>
0

If the Sprite image contains multiple frames you can specify which one to use here. Or an Array of frames. See the description for details on how the quantity applies when arrays are used.

exists boolean <optional>
false

The default exists state of the Sprite.

Returns
array -

An array containing all of the Sprites that were created.

Inherited From
Source code: core/Group.js (Line 581)
doc_phaser
2017-02-14 10:57:08
Comments
Leave a Comment

Please login to continue.