Game Development Reference
In-Depth Information
setDuration() : This sets the overall duration the particle effect will run
setPosition() : This sets the position to where it will be drawn
setFlip() : This sets the horizontal and vertical flip modes
save() : This saves a particle effect with all its settings to a file
load() : This loads a particle effect with all its settings from a saved file
dispose() : This frees all the resources allocated by the particle effect
Using an instance of ParticleEffect alone will not yield anything visible on the
screen yet. This is because particles are represented as images and this class does not
have such a reference to an image. Instead, an instance of the ParticleEmitter class
is required, which among other attributes can take a reference to an image for the
particles to be rendered. An emitter manages particles that use the same image. The
particles of an emitter also share the same specific behavior, which is usually given in
ranged values. These ranged values define the range to generate random values for
each spawned particle, which will make the resulting effect look much more natural.
If needed, several emitters can be added to a single effect in order to create more
complex particle effects that use multiple images and collective behavior.
The following code is an example of how to create a particle effect with one emitter:
ParticleEffect effect = new ParticleEffect();
ParticleEmitter emitter = new ParticleEmitter();
effect.getEmitters().add(emitter);
emitter.setAdditive(true);
emitter.getDelay().setActive(true);
emitter.getDelay().setLow(0.5f);
// ... more code for emitter initialization ...
While there is absolutely nothing wrong with this approach in general, it is not
recommended to initialize particle emitters in code. Emitters contain roughly
20 attributes that can be played with, so it is quite obvious at this point that this
approach will lead very quickly to a lot of code snippets that are hard to understand
and maintain. A much cleaner and fun solution is to use LibGDX's graphical particle
editor in order to create new particle effects or modify the existing ones. The editor
features a live preview of the current settings of the particle effect, which simplifies
the design phase a lot. The preview gives direct feedback on the final result of the
particle effect as well as how changed attributes alter the effect.
You can download and run the latest editor by entering http://wiki.libgdx.
googlecode.com/git/jws/particle-editor.jnlp in your browser.
 
Search WWH ::




Custom Search