pslib
Class TemplateEmission

java.lang.Object
  extended by pslib.TemplateEmission
All Implemented Interfaces:
PSBehaviour, PSEmission

public class TemplateEmission
extends java.lang.Object
implements PSEmission

TemplateEmission Class

The TemplateEmission class implements the PSEmission interface allowing the automated emission of random particles derived from the object variables from any emitters to which it is assigned.

Unlike the VariantEmission class, individual particle parameters may have independent variance and may be subject to modification after creation.

This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.

See Also:
VariantEmission

Constructor Summary
TemplateEmission(DynamicParticle t, int ep, int mi, int ma)
          Create a new object instance with the specified variables
TemplateEmission(WeightedList<DynamicParticle> t, int ep, int mi, int ma)
          Create a new object instance with the specified variables
 
Method Summary
 void addListener(ParticleListener p)
          Attach a particle listener
 void clearListeners()
          Clear all attached particle listeners
 boolean removeListener(ParticleListener p)
          Remove a particle listener
 void setActive(boolean a)
          Set the active state of the behaviour
 void setAlpha(float a, int v)
          Set the emitted particle alpha value and variance
 void setDecay(int d, int v)
          Set the emitted particle decay value and variance
 void setEmissionProbability(int p)
          Set the emission probability
 void setEmittedParticles(int p)
          Set the amount of particles emitted on each emission event
 void setEmittedParticles(int min, int max)
          Set the amount of particles emitted on each emission event
 void setPalette(WeightedList<PSColour> p)
          Set the particle colour palette
 void setSize(float s, int v)
          Set the emitted particle size value and variance
 void setTemplate(WeightedList<DynamicParticle> t)
          Set the particle template
 void update(DynamicParticle p)
          Update the specified particle (unused)
 void update(GenericEmitter e)
          Update the specified emitter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplateEmission

public TemplateEmission(DynamicParticle t,
                        int ep,
                        int mi,
                        int ma)
Create a new object instance with the specified variables

Default decay, size and alpha values are taken from the specified particle with 0% variance.

Parameters:
t - particle template
ep - emission probability
mi - minimum emitted particles
ma - maximum emitted particles

TemplateEmission

public TemplateEmission(WeightedList<DynamicParticle> t,
                        int ep,
                        int mi,
                        int ma)
Create a new object instance with the specified variables

Default decay, size and alpha values are taken from a particle selected at random from the specified list with 0% variance.

Parameters:
t - particle template list
ep - emission probability
mi - minimum emitted particles
ma - maximum emitted particles
Method Detail

setTemplate

public final void setTemplate(WeightedList<DynamicParticle> t)
Set the particle template

The particle template specifies the list of particles from which emitted particles may be derived. If no palette is specified emitted particles will inherit their colour from the template.

Parameters:
t - particle template

setPalette

public final void setPalette(WeightedList<PSColour> p)
Set the particle colour palette

The particle colour palette specifies the list of colours from which emitted particles may select. If no palette is specified emitted particles will inherit their colour from the particle template.

Parameters:
p - colour palette

setActive

public final void setActive(boolean a)
Set the active state of the behaviour

A value of true will result in particle emission on the update routine of any emitters to which this behaviour is attached.

Default: true

Specified by:
setActive in interface PSEmission
Parameters:
a -

setEmissionProbability

public final void setEmissionProbability(int p)
Set the emission probability

The emission probability specifies the probability of particle creation in the format 1:probability.

Parameters:
p - emission probability

setEmittedParticles

public final void setEmittedParticles(int p)
Set the amount of particles emitted on each emission event

Parameters:
p - particles

setEmittedParticles

public final void setEmittedParticles(int min,
                                      int max)
Set the amount of particles emitted on each emission event

The actual amount of emitted particles will be derived at random from the specified range.

Parameters:
min - minimum particles
max - maximum particles

setDecay

public final void setDecay(int d,
                           int v)
Set the emitted particle decay value and variance

Parameters:
d - decay (ms)
v - variance (+/- %)

setSize

public final void setSize(float s,
                          int v)
Set the emitted particle size value and variance

Parameters:
s - size
v - variance (+/- %)

setAlpha

public final void setAlpha(float a,
                           int v)
Set the emitted particle alpha value and variance

Parameters:
a - alpha
v - variance (+/- %)

update

public void update(GenericEmitter e)
Update the specified emitter

The update routine attaches random particles derived from the object variables to the specified emitter. References to created particles are sent to any attached listeners.

Specified by:
update in interface PSEmission
Parameters:
e - emitter

update

public void update(DynamicParticle p)
Update the specified particle (unused)

Specified by:
update in interface PSBehaviour
Parameters:
p - particle

addListener

public final void addListener(ParticleListener p)
Attach a particle listener

Attached listeners will receive a reference to created particles upon emission. If this object is assigned as behaviour to multiple emitters, attached listeners will receive particles from each.

Parameters:
p - particle listener

removeListener

public final boolean removeListener(ParticleListener p)
Remove a particle listener

Parameters:
p - particle listener
Returns:
false if the listener does not exist

clearListeners

public final void clearListeners()
Clear all attached particle listeners