jme.entity.effects
Class ParticleEmitter

java.lang.Object
  extended byjme.entity.effects.ParticleEmitter

public class ParticleEmitter
extends java.lang.Object

ParticleEmitter controls and maintains a number of Particles. The emitter handles creation of a particle setting the particles attributes to those defined by the user creating the emitter. An emitter updates the particle during a call to update setting it's new position, size, color and transparency. Size and color have a start and end value, where these values are interpolated through the life of the particle. Another important note is that the gravity value is what handles the updating of the velocity of individual particles. When a particle is first created, it's velocity is in a random direction. It is not until the gravity takes hold that it will travel in the desired direction. This adds realism to the particle emitter.

Version:
$Id: ParticleEmitter.java,v 1.3 2003/09/03 18:05:36 mojomonkey Exp $
Author:
Mark Powell

Constructor Summary
ParticleEmitter(int numParticles)
          Constructor instantiates a new ParticleEmitter object, intializing the particle array for the number of particles this emitter is responsible for.
 
Method Summary
 void loopAnimation(boolean value)
          loopAnimation determines whether to continue animating the particles after the first batch.
 void render()
          render renders a quad for each particle using a billboarding effect so that the particle is always facing the viewport.
 void setEndColor(Vector endColor)
          setEndColor sets the final color of the particle just before it dies.
 void setEndSize(Vector endSize)
          setEndSize sets the final size of the particle just before it dies.
 void setFade(float fade)
          setFade sets the fade value of the particles.
 void setFriction(float friction)
          setFriction sets the value that the particles slow down during their travels.
 void setGravity(Vector gravity)
          setGravity sets the value of the forces that will be acting upon the particles.
 void setPosition(Vector position)
          setPosition sets the position of the emitter.
 void setSpeed(float speed)
          setSpeed sets the speed at which the particle engine updates.
 void setStartColor(Vector startColor)
          setStartColor sets the starting color of the particle.
 void setStartSize(Vector startSize)
          setStartSize sets the starting size of the particle.
 void setTexture(java.lang.String filename)
          setTexture assigns the texture to be associated with the particles.
 void update(float timeFraction)
          update updates each particles position, velocity, life, color and size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParticleEmitter

public ParticleEmitter(int numParticles)
Constructor instantiates a new ParticleEmitter object, intializing the particle array for the number of particles this emitter is responsible for.

Parameters:
numParticles - the number of particles that will be on screen at any one time.
Method Detail

update

public void update(float timeFraction)
update updates each particles position, velocity, life, color and size. If a particles life has reached zero, it is considered dead and will be replaced by a new particle.

Parameters:
timeFraction - the time factor between frames.

render

public void render()
render renders a quad for each particle using a billboarding effect so that the particle is always facing the viewport. This gives us a very good three dimensional effect using two dimensional objects.


setFriction

public void setFriction(float friction)
setFriction sets the value that the particles slow down during their travels. A typical value will be anywhere between 1 and 10. A negative value will cause the particle to travel in the opposite direction.

Parameters:
friction - the new friction value.

setEndColor

public void setEndColor(Vector endColor)
setEndColor sets the final color of the particle just before it dies. This color is interpolated with the start color.

Parameters:
endColor - the final color of the particle.

setEndSize

public void setEndSize(Vector endSize)
setEndSize sets the final size of the particle just before it dies. This size is interpolated with the start size.

Parameters:
endSize - the final size of the particle.

setGravity

public void setGravity(Vector gravity)
setGravity sets the value of the forces that will be acting upon the particles. This value is what determines the direction of the particles velocity.

Parameters:
gravity - the forces that will be acting on the particle.

setStartColor

public void setStartColor(Vector startColor)
setStartColor sets the starting color of the particle. This color is interpolated with the final color.

Parameters:
startColor - the starting color of the particles.

setStartSize

public void setStartSize(Vector startSize)
setStartSize sets the starting size of the particle. This size is interpolated with the final size.

Parameters:
startSize - the starting size of the particles.

setFade

public void setFade(float fade)
setFade sets the fade value of the particles. The final fade value is determined by multiplying the fade value by two and then multiplying by a random number between 0 and 1. Therefore, the fade value determines the minimum and fade * 2 is the maximum.

Parameters:
fade - the fade value of the particles.

setPosition

public void setPosition(Vector position)
setPosition sets the position of the emitter. This will determine the initial position of each particle as they are generated.

Parameters:
position -

setSpeed

public void setSpeed(float speed)
setSpeed sets the speed at which the particle engine updates. By default the speed is 1.

Parameters:
speed - the speed of the updates.

setTexture

public void setTexture(java.lang.String filename)
setTexture assigns the texture to be associated with the particles.

Parameters:
filename - the image file of the texture.

loopAnimation

public void loopAnimation(boolean value)
loopAnimation determines whether to continue animating the particles after the first batch. That is, a fire would continue to burn, but there would only be a single explosion.

Parameters:
value - true loop, false only create a single batch.