ParticleEmitter Class
The ParticleEmitter is the object that is placed in the world and will fire off particles based on the rules and properties set on it. Generally you will want to create/use these by adding them to a ParticleSystem.
Constructor
ParticleEmitter
-
name
Parameters:
-
name
StringThe string name of the particle emitter.
Item Index
Methods
Properties
Methods
_free
-
sprite
Frees a particle back into the pool and hides it.
Parameters:
-
sprite
SpriteThe particle to free
_get
()
Sprite
private
Gets a particle from the pool and sets it up.
Returns:
The particle to use
addChildAt
-
child
-
index
Adds a child to the object at a specified index. If the index is out of bounds an error will be thrown
destroy
()
Destroys this object.
destroyAllChildren
()
Container
chainable
Destroys all the children of the object.
Returns:
Returns itself.
disablePhysics
()
Mixed
chainable
async
Disbales physics for this sprite
Returns:
Returns itself.
emit
-
type
-
data
Emits an event which will run all registered listeners for the event type
Parameters:
-
type
StringThe event name to emit
-
data
MixedAny data you want passed along with the event
Returns:
Returns itself.
emitParticle
()
ParticleEmitter
chainable
Emits a single particle and sets the position, scale, lifespan, and velocity
Returns:
Returns itself.
enablePhysics
-
system
Enables physics for this sprite
Parameters:
-
system
PhysicsSystemThe system for the sprite to be in
Returns:
Returns itself.
hide
()
Container
chainable
Sets the container to visible = false
Returns:
Returns itself.
off
-
type
-
listener
Removes a listener function for an event type
Parameters:
-
type
StringThe event name to emit
-
listener
FunctionThe function to remove
Returns:
Returns itself.
on
-
type
-
listener
Registers a listener function to be run on an event occurance
Parameters:
-
type
StringThe event name to listen for
-
listener
FunctionThe function to execute when the event happens
Returns:
Returns itself.
once
-
type
-
listener
Registers a one-time callback for an event
Parameters:
-
type
StringThe event name to listen for
-
listener
Functionthe callback to call when the event occurs
Returns:
Returns itself.
onCollide
-
obj
-
collision
Called whenever a collision occurs
Parameters:
Returns:
If you return false
explicitly the engine will not
solve the collision. In this way you can make thing "not collide" if
you don't want their types to collide.
removeAllChildren
()
Container
chainable
Removes all children from the object.
Returns:
Returns itself.
setMass
-
mass
Sets the mass of this sprite
Parameters:
-
mass
NumberThe new mass of the object
Returns:
Returns itself.
setPosition
-
x
-
y
Sets the position of this sprite
Parameters:
-
x
Number -
y
Number
Returns:
Returns itself.
setRotation
-
rotation
Sets the rotation of this sprite
Parameters:
-
rotation
NumberThe new rotation of the object in radians
Returns:
Returns itself.
setup
-
sprite
-
[collide=gf.DIRECTION.ALL]
Sets up the particles to be emitted
Parameters:
-
sprite
Sprite | Array| Texture Pass a sprite to be clones as a particle, or an array of textures to be randomly chosen from for different particles, or a single texture to use for each particle.
-
[collide=gf.DIRECTION.ALL]
Number optionalThe directions the particles are allowed to collide in, use gf.DIRECTION bit flags
Returns:
Returns itself.
setVelocity
-
velocity
Sets the velocity of this sprite
Parameters:
-
velocity
VectorThe new velocity of the object
Returns:
Returns itself.
show
()
Container
chainable
Sets the container to visible = true
Returns:
Returns itself.
start
-
[lifespan=2000]
-
[delay=250]
-
[rate=1]
-
[total=gf.PARTICLES.MAX_EMITTER_PARTICLES]
Starts the particle emission, must call setup
first to setup
what kind of particle to emit.
Parameters:
-
[lifespan=2000]
Number optionalThe lifespan of a particle in ms
-
[delay=250]
Number optionalThe time between each particle emission in ms
-
[rate=1]
Number optionalThe number of particles to emit each emission
-
[total=gf.PARTICLES.MAX_EMITTER_PARTICLES]
Number optionalThe total number of particles to emit
Returns:
Returns itself.
stop
()
ParticleEmitter
chainable
Deactivates the emitter. Particles that are already emitted will continue to decay and die, but no new particles will be emitted.
Returns:
Returns itself.
update
-
dt
Called internally by the ParticleSystem each frame to update each particle's lifespan.
Parameters:
-
dt
NumberThe number of seconds that have passed since last call
Properties
_phys
Object
private
The physics namespace that all physics properties go into. Those properties are:
- system {PhysicsSystem} PhysicsSystem that this object is a part of.
- active {Boolean} Whether or not this target is actively having physics simulated.
Default: {}
active
Boolean
If true the emitter will emit particles, otherwise it will not.
Default: false
alpha
Number
The opacity of the object.
children
Array
[read-only] The of children of this object.
delay
Number
The time in milliseconds between emissions of particles
Default: 100
height
Number
The height of the emitter, particles are emitted in a random integer location within the width and height of the emitter.
Default: 0
hitArea
Rectangle | Polygon | Circle | Ellipse
This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)
inertia
Number
The moment of inertia of this object, only set this before enabling physics (has no effect after enabling)
Default: 0
interactive
Boolean
Wether or not the object will handle mouse events
Default: false
lifespan
Number
The default lifespan of a particle that is emitted by this ParticleEmitter, in milliseconds
Default: 2000
mass
Number
The mass of this object, please use setMass to set this value
Default: 0
maxParticles
Number
The maximum number of particles an emitter can have active at any time.
Default: 100
maxRotation
Number
The default maxRotation of a particle that is emitted by this ParticleEmitter
The actual rotation will be a random integer between minRotation
and maxRotation
.
Default: 2 * Math.PI
maxScale
Number
The default maxScale of a particle that is emitted by this ParticleEmitter
The actual scale will be a random number between minScale
and maxScale
.
Default: 1
maxSpeed
Vector
The default maxSpeed of a particle that is emitted by this ParticleEmitter
The actual speed will be a random Vector between minSpeed
and maxSpeed
.
Default: new Vector(100, 100)
minRotation
Number
The default minRotation of a particle that is emitted by this ParticleEmitter
The actual rotation will be a random integer between minRotation
and maxRotation
.
Default: -2 * Math.PI
minScale
Number
The default minScale of a particle that is emitted by this ParticleEmitter
The actual scale will be a random number between minScale
and maxScale
.
Default: 1
minSpeed
Vector
The default minSpeed of a particle that is emitted by this ParticleEmitter
The actual speed will be a random Vector between minSpeed
and maxSpeed
.
Default: new Vector(-100, 100)
name
String
The name of the ParticleEmitter instance. This should be unique in a system, and set by the param passed to the constructor.
parent
DisplayObject
[read-only] The display object that contains this display object.
particles
ArrayThe internal pool to create and reuse particles from
position
Point
The coordinate of the object relative to the local coordinates of the parent.
rotation
Number
The rotation of the object in radians.
scale
Point
The scale factor of the object.
stage
Stage
[read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.
visible
Boolean
The visibility of the object.
width
Number
The width of the emitter, particles are emitted in a random integer location within the width and height of the emitter.
Default: 0
Events
click
A callback that is used when the users clicks on the displayObject with their mouse
Event Payload:
-
interactionData
InteractionData
collision
On Collision Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for
mousedown
A callback that is used when the user clicks the mouse down over the displayObject
Event Payload:
-
interactionData
InteractionData
mousemove
A callback that is used when the user moves the mouse while over the displayObject
Event Payload:
-
interactionData
InteractionData
mouseout
A callback that is used when the users mouse leaves the displayObject
Event Payload:
-
interactionData
InteractionData
mouseover
A callback that is used when the users mouse rolls over the displayObject
Event Payload:
-
interactionData
InteractionData
mouseup
A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject
Event Payload:
-
interactionData
InteractionData
mouseupoutside
A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject
Event Payload:
-
interactionData
InteractionData
separate
On Seperate Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for
Event Payload:
-
obj
SpriteColliding sprite
-
colShape
cp.ShapeThe colliding physics shape
-
myShape
cp.ShapeYour physics shape that caused the collision
tap
A callback that is used when the users taps on the displayObject with their finger basically a touch version of click
Event Payload:
-
interactionData
InteractionData
touchend
A callback that is used when the user releases a touch over the displayObject
Event Payload:
-
interactionData
InteractionData
touchendoutside
A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the displayObject
Event Payload:
-
interactionData
InteractionData
touchstart
A callback that is used when the user touch's over the displayObject
Event Payload:
-
interactionData
InteractionData