Class: Emitter

Emitter

Emitter is a lightweight particle emitter. It can be used for one-time explosions or for continuous effects like rain and fire. All it really does is launch Particle objects out at set intervals, and fixes their positions and velocities accorindgly.

new Emitter(game, x, y, maxParticles)

Phaser - ArcadeEmitter

Parameters:
Name Type Argument Default Description
game Phaser.Game

Current game instance.

x number <optional>
0

The x coordinate within the Emitter that the particles are emitted from.

y number <optional>
0

The y coordinate within the Emitter that the particles are emitted from.

maxParticles number <optional>
50

The total number of particles in this emitter..

Source:

Extends

Members

alpha

The emitters alpha value.

Properties:
Name Type Description
alpha number

Gets or sets the alpha value of the Emitter.

Source:

angle

The angle of rotation of the Group container. This will adjust the Group container itself by modifying its rotation. This will have no impact on the rotation value of its children, but it will update their worldTransform and on-screen position.

Properties:
Name Type Description
angle number

The angle of rotation given in degrees, where 0 degrees = to the right.

Inherited From:
Source:

angularDrag

The angular drag component of particles launched from the emitter if they are rotating.

Properties:
Name Type Description
angularDrag number
Default Value:
  • 0
Source:

<readonly> bottom

Properties:
Name Type Description
bottom number

Gets the bottom position of the Emitter.

Source:

bounce

How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.

Properties:
Name Type Description
bounce Phaser.Point
Source:

emitX

The point the particles are emitted from. Emitter.x and Emitter.y control the containers location, which updates all current particles Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.

Properties:
Name Type Description
emitX boolean
Source:

emitY

The point the particles are emitted from. Emitter.x and Emitter.y control the containers location, which updates all current particles Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.

Properties:
Name Type Description
emitY boolean
Source:

exists

Determines whether the emitter is being updated by the core game loop.

Properties:
Name Type Description
exists boolean
Default Value:
  • true
Source:

frequency

How often a particle is emitted in ms (if emitter is started with Explode == false).

Properties:
Name Type Description
frequency boolean
Default Value:
  • 100
Source:

game

Properties:
Name Type Description
game Phaser.Game

A reference to the currently running Game.

Inherited From:
Source:

gravity

Sets the <code>gravity.y</code> of each particle to this value on launch.

Properties:
Name Type Description
gravity number
Default Value:
  • 2
Source:

height

Properties:
Name Type Description
height number

The height of the emitter. Particles can be randomly generated from anywhere within this box.

Default Value:
  • 1
Source:

<readonly> left

Properties:
Name Type Description
left number

Gets the left position of the Emitter.

Source:

<readonly> length

Properties:
Name Type Description
length number

The number of children in this Group.

Inherited From:
Source:

lifespan

How long each particle lives once it is emitted in ms. Default is 2 seconds. Set lifespan to 'zero' for particles to live forever.

Properties:
Name Type Description
lifespan number
Default Value:
  • 2000
Source:

maxParticles

The total number of particles in this emitter.

Properties:
Name Type Description
maxParticles number

The total number of particles in this emitter..

Source:

maxParticleScale

The maximum possible scale of a particle. The default value is 1.

Properties:
Name Type Description
maxParticleScale number
Default Value:
  • 1
Source:

maxParticleSpeed

The maximum possible velocity of a particle. The default value is (100,100).

Properties:
Name Type Description
maxParticleSpeed Phaser.Point
Source:

maxRotation

The maximum possible angular velocity of a particle. The default value is 360.

Properties:
Name Type Description
maxRotation number
Default Value:
  • 360
Source:

minParticleScale

The minimum possible scale of a particle. The default value is 1.

Properties:
Name Type Description
minParticleScale number
Default Value:
  • 1
Source:

minParticleSpeed

The minimum possible velocity of a particle. The default value is (-100,-100).

Properties:
Name Type Description
minParticleSpeed Phaser.Point
Source:

minRotation

The minimum possible angular velocity of a particle. The default value is -360.

Properties:
Name Type Description
minRotation number
Source:

name

Properties:
Name Type Description
name string

Description.

Source:

on

Determines whether the emitter is currently emitting particles. It is totally safe to directly toggle this.

Properties:
Name Type Description
on boolean
Default Value:
  • false
Source:

particleClass

Set your own particle class type here.

Properties:
Name Type Description
particleClass Description
Default Value:
  • null
Source:

particleDrag

The X and Y drag component of particles launched from the emitter.

Properties:
Name Type Description
particleDrag Phaser.Point
Source:
Properties:
Name Type Description
right number

Gets the right position of the Emitter.

Source:

rotation

The angle of rotation of the Group container. This will adjust the Group container itself by modifying its rotation. This will have no impact on the rotation value of its children, but it will update their worldTransform and on-screen position.

Properties:
Name Type Description
rotation number

The angle of rotation given in radians.

Inherited From:
Source:

<readonly> top

Properties:
Name Type Description
top number

Gets the top position of the Emitter.

Source:

type

Properties:
Name Type Description
type Description

Description.

Source:

visible

The emitter visible state.

Properties:
Name Type Description
visible boolean

Gets or sets the Emitter visible state.

Source:

width

Properties:
Name Type Description
width number

The width of the emitter. Particles can be randomly generated from anywhere within this box.

Default Value:
  • 1
Source:

x

Properties:
Name Type Description
x number

Gets or sets the x position of the Emitter.

Source:

x

Properties:
Name Type Description
x number

The X position of the top left corner of the emitter in world space.

Default Value:
  • 0
Source:

y

Properties:
Name Type Description
y number

Gets or sets the y position of the Emitter.

Source:

y

Properties:
Name Type Description
y number

The Y position of the top left corner of emitter in world space.

Default Value:
  • 0
Source:

Methods

add(child) → {*}

Adds an existing object to this Group. The object can be an instance of Phaser.Sprite, Phaser.Button or any other display object. The child is automatically added to the top of the Group, so renders on-top of everything else within the Group. If you need to control that then see the addAt method.

Parameters:
Name Type Description
child *

An instance of Phaser.Sprite, Phaser.Button or any other display object..

Inherited From:
Source:
See:
Returns:

The child that was added to the Group.

Type
*

addAll(property, amount, checkAlive, checkVisible)

Adds the amount to the given property on all children in this Group. Group.addAll('x', 10) will add 10 to the child.x value.

Parameters:
Name Type Description
property string

The property to increment, for example 'body.velocity.x' or 'angle'.

amount number

The amount to increment the property by. If child.x = 10 then addAll('x', 40) would make child.x = 50.

checkAlive boolean

If true the property will only be changed if the child is alive.

checkVisible boolean

If true the property will only be changed if the child is visible.

Inherited From:
Source:

addAt(child, index) → {*}

Adds an existing object to this Group. The object can be an instance of Phaser.Sprite, Phaser.Button or any other display object. The child is added to the Group at the location specified by the index value, this allows you to control child ordering.

Parameters:
Name Type Description
child *

An instance of Phaser.Sprite, Phaser.Button or any other display object..

index number

The index within the Group to insert the child to.

Inherited From:
Source:
Returns:

The child that was added to the Group.

Type
*

at(object)

Change the emitter's midpoint to match the midpoint of a <code>Object</code>.

Parameters:
Name Type Description
object object

The <code>Object</code> that you want to sync up with.

Source:

bringToTop(child) → {*}

Brings the given child to the top of this Group so it renders above all other children.

Parameters:
Name Type Description
child *

The child to bring to the top of this Group.

Inherited From:
Source:
Returns:

The child that was moved.

Type
*

callAll(callback, parameter)

Calls a function on all of the children regardless if they are dead or alive (see callAllExists if you need control over that) After the callback parameter you can add as many extra parameters as you like, which will all be passed to the child.

Parameters:
Name Type Argument Description
callback function

The function that exists on the children that will be called.

parameter * <repeatable>

Additional parameters that will be passed to the callback.

Inherited From:
Source:

callAllExists(callback, existsValue, parameter)

Calls a function on all of the children that have exists=true in this Group. After the existsValue parameter you can add as many parameters as you like, which will all be passed to the child callback.

Parameters:
Name Type Argument Description
callback function

The function that exists on the children that will be called.

existsValue boolean

Only children with exists=existsValue will be called.

parameter * <repeatable>

Additional parameters that will be passed to the callback.

Inherited From:
Source:

countDead() → {number}

Call this function to find out how many members of the group are dead.

Inherited From:
Source:
Returns:

The number of children flagged as dead. Returns -1 if Group is empty.

Type
number

countLiving() → {number}

Call this function to find out how many members of the group are alive.

Inherited From:
Source:
Returns:

The number of children flagged as alive. Returns -1 if Group is empty.

Type
number

create(x, y, key, frame, exists) → {Phaser.Sprite}

Automatically creates a new Phaser.Sprite object and adds it to the top of this Group. Useful if you don't need to create the Sprite instances before-hand.

Parameters:
Name Type Argument Description
x number

The x coordinate to display the newly created Sprite at. The value is in relation to the Group.x point.

y number

The y coordinate to display the newly created Sprite at. The value is in relation to the Group.y point.

key string

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

frame number | string <optional>

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

exists boolean <optional>

The default exists state of the Sprite.

Inherited From:
Source:
Returns:

The child that was created.

Type
Phaser.Sprite

destroy()

Destroys this Group. Removes all children, then removes the container from the display list and nulls references.

Inherited From:
Source:

divideAll(property, amount, checkAlive, checkVisible)

Divides the given property by the amount on all children in this Group. Group.divideAll('x', 2) will half the child.x value.

Parameters:
Name Type Description
property string

The property to divide, for example 'body.velocity.x' or 'angle'.

amount number

The amount to divide the property by. If child.x = 100 then divideAll('x', 2) would make child.x = 50.

checkAlive boolean

If true the property will only be changed if the child is alive.

checkVisible boolean

If true the property will only be changed if the child is visible.

Inherited From:
Source:

dump(full)

Dumps out a list of Group children and their index positions to the browser console. Useful for group debugging.

Parameters:
Name Type Argument Default Description
full boolean <optional>
false

If full the dump will include the entire display list, start from the Stage. Otherwise it will only include this container.

Inherited From:
Source:

emitParticle()

This function can be used both internally and externally to emit the next particle.

Source:

forEach(callback, callbackContext, checkExists)

Allows you to call your own function on each member of this Group. You must pass the callback and context in which it will run. After the checkExists parameter you can add as many parameters as you like, which will all be passed to the callback along with the child. For example: Group.forEach(awardBonusGold, this, true, 100, 500)

Parameters:
Name Type Description
callback function

The function that will be called. Each child of the Group will be passed to it as its first parameter.

callbackContext Object

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

checkExists boolean

If set only children with exists=true will be passed to the callback, otherwise all children will be passed.

Inherited From:
Source:

forEachAlive(callback, callbackContext)

Allows you to call your own function on each alive member of this Group (where child.alive=true). You must pass the callback and context in which it will run. You can add as many parameters as you like, which will all be passed to the callback along with the child. For example: Group.forEachAlive(causeDamage, this, 500)

Parameters:
Name Type Description
callback function

The function that will be called. Each child of the Group will be passed to it as its first parameter.

callbackContext Object

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

Inherited From:
Source:

forEachDead(callback, callbackContext)

Allows you to call your own function on each dead member of this Group (where alive=false). You must pass the callback and context in which it will run. You can add as many parameters as you like, which will all be passed to the callback along with the child. For example: Group.forEachDead(bringToLife, this)

Parameters:
Name Type Description
callback function

The function that will be called. Each child of the Group will be passed to it as its first parameter.

callbackContext Object

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

Inherited From:
Source:

getAt(index) → {*}

Returns the child found at the given index within this Group.

Parameters:
Name Type Description
index number

The index to return the child from.

Inherited From:
Source:
Returns:

The child that was found at the given index.

Type
*

getFirstAlive() → {Any}

Call this function to retrieve the first object with alive == true in the group. This is handy for checking if everything has been wiped out, or choosing a squad leader, etc.

Inherited From:
Source:
Returns:

The first alive child, or null if none found.

Type
Any

getFirstDead() → {Any}

Call this function to retrieve the first object with alive == false in the group. This is handy for checking if everything has been wiped out, or choosing a squad leader, etc.

Inherited From:
Source:
Returns:

The first dead child, or null if none found.

Type
Any

getFirstExists(state) → {Any}

Call this function to retrieve the first object with exists == (the given state) in the Group.

Parameters:
Name Type Description
state boolean

True or false.

Inherited From:
Source:
Returns:

The first child, or null if none found.

Type
Any

getIndex(child) → {number}

Get the index position of the given child in this Group.

Parameters:
Name Type Description
child *

The child to get the index for.

Inherited From:
Source:
Returns:

The index of the child or -1 if it's not a member of this Group.

Type
number

getRandom(startIndex, length) → {Any}

Returns a member at random from the group.

Parameters:
Name Type Description
startIndex number

Optional offset off the front of the array. Default value is 0, or the beginning of the array.

length number

Optional restriction on the number of values you want to randomly select from.

Inherited From:
Source:
Returns:

A random child of this Group.

Type
Any

kill()

Call this function to turn off all the particles and the emitter.

Source:

makeParticles(keys, frames, quantity, collide, collideWorldBounds)

This function generates a new array of particle sprites to attach to the emitter.

Parameters:
Name Type Description
keys Description

Description.

frames number

Description.

quantity number

The number of particles to generate when using the "create from image" option.

collide number

Description.

collideWorldBounds boolean

Description.

Source:
Returns:

This Emitter instance (nice for chaining stuff together, if you're into that).

multiplyAll(property, amount, checkAlive, checkVisible)

Multiplies the given property by the amount on all children in this Group. Group.multiplyAll('x', 2) will x2 the child.x value.

Parameters:
Name Type Description
property string

The property to multiply, for example 'body.velocity.x' or 'angle'.

amount number

The amount to multiply the property by. If child.x = 10 then multiplyAll('x', 2) would make child.x = 20.

checkAlive boolean

If true the property will only be changed if the child is alive.

checkVisible boolean

If true the property will only be changed if the child is visible.

Inherited From:
Source:

remove(child)

Removes the given child from this Group and sets its group property to null.

Parameters:
Name Type Description
child Any

The child to remove.

Inherited From:
Source:

removeAll()

Removes all children from this Group, setting all group properties to null. The Group container remains on the display list.

Inherited From:
Source:

removeBetween(startIndex, endIndex)

Removes all children from this Group whos index falls beteen the given startIndex and endIndex values.

Parameters:
Name Type Description
startIndex number

The index to start removing children from.

endIndex number

The index to stop removing children from. Must be higher than startIndex and less than the length of the Group.

Inherited From:
Source:

replace(oldChild, newChild)

Replaces a child of this Group with the given newChild. The newChild cannot be a member of this Group.

Parameters:
Name Type Description
oldChild *

The child in this Group that will be replaced.

newChild *

The child to be inserted into this group.

Inherited From:
Source:

revive()

Handy for bringing game objects "back to life". Just sets alive and exists back to true. In practice, this is most often called by <code>Object.reset()</code>.

Source:

setAll(key, value, checkAlive, checkVisible, operation)

This function allows you to quickly set the same property across all children of this Group to a new value. The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.

Parameters:
Name Type Argument Default Description
key string

The property, as a string, to be set. For example: 'body.velocity.x'

value *

The value that will be set.

checkAlive boolean <optional>
false

If set then only children with alive=true will be updated.

checkVisible boolean <optional>
false

If set then only children with visible=true will be updated.

operation number <optional>
0

Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.

Inherited From:
Source:

setProperty(child, key, value, operation)

Sets the given property to the given value on the child. The operation controls the assignment of the value.

Parameters:
Name Type Argument Default Description
child *

The child to set the property value on.

key array

An array of strings that make up the property that will be set.

value *

The value that will be set.

operation number <optional>
0

Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.

Inherited From:
Source:

setRotation(min, max)

A more compact way of setting the angular velocity constraints of the emitter.

Parameters:
Name Type Description
min number

The minimum value for this range.

max number

The maximum value for this range.

Source:

setSize(width, height)

A more compact way of setting the width and height of the emitter.

Parameters:
Name Type Description
width number

The desired width of the emitter (particles are spawned randomly within these dimensions).

height number

The desired height of the emitter.

Source:

setXSpeed(min, max)

A more compact way of setting the X velocity range of the emitter.

Parameters:
Name Type Description
min number

The minimum value for this range.

max number

The maximum value for this range.

Source:

setYSpeed(min, max)

A more compact way of setting the Y velocity range of the emitter.

Parameters:
Name Type Description
min number

The minimum value for this range.

max number

The maximum value for this range.

Source:

start(explode, lifespan, frequency, quantity)

Call this function to start emitting particles.

Parameters:
Name Type Description
explode boolean

Whether the particles should all burst out at once.

lifespan number

How long each particle lives once emitted. 0 = forever.

frequency number

Ignored if Explode is set to true. Frequency is how often to emit a particle in ms.

quantity number

How many particles to launch. 0 = "all of the particles".

Source:

subAll(property, amount, checkAlive, checkVisible)

Subtracts the amount from the given property on all children in this Group. Group.subAll('x', 10) will minus 10 from the child.x value.

Parameters:
Name Type Description
property string

The property to decrement, for example 'body.velocity.x' or 'angle'.

amount number

The amount to subtract from the property. If child.x = 50 then subAll('x', 40) would make child.x = 10.

checkAlive boolean

If true the property will only be changed if the child is alive.

checkVisible boolean

If true the property will only be changed if the child is visible.

Inherited From:
Source:

swap(child1, child2) → {boolean}

Swaps the position of two children in this Group.

Parameters:
Name Type Description
child1 *

The first child to swap.

child2 *

The second child to swap.

Inherited From:
Source:
Returns:

True if the swap was successful, otherwise false.

Type
boolean

update()

Called automatically by the game loop, decides when to launch particles and when to "die".

Source:
Phaser Copyright © 2012-2013 Photon Storm Ltd.
Documentation generated by JSDoc 3.2.0-dev on Thu Oct 03 2013 02:35:48 GMT+0100 (BST) using the DocStrap template.