Game Development Reference
In-Depth Information
How to do it…
In the first section, we'll create a new
ParticleInfluencer
instance. This consists of
the following steps:
1. The first thing we'll do is create a new class called
BirdParticleInfluen-
cer
and have it extend the
DefaultParticleInfluencer
class. Since the
flat particles point in the direction they're flying, it sometimes looks weird when
they have a Y-velocity. We're going to fix that by not allowing the particles to have
any velocity in the
y
axis. We override the
influenceParticle
method and
set the Y-velocity to
0
. After this we need to normalize the velocity, as shown in
the following code:
public void influenceParticle(Particle particle,
EmitterShape emitterShape) {
super.influenceParticle(particle, emitterShape);
particle.velocity.setY(0);
particle.velocity.normalizeLocal();
}
2. We can now replace the
ParticleInfluencer
interface in the
ParticleEmitter
element's
Property
window with our own.
3. That was the easy part, and that's how far we get without modifying the engine. In
the next section, we will extend the current
ParticleEmitter
instance to an-
imate particles continuously. This will consist of the following steps:
1. Let's start by making our
ParticleInfluencer
interface ready to up-
date the particles in every frame. Let's start by making our
ParticleInfluencer
interface ready to update the particles in every
frame. We're going to add two methods to it. The first one is for updating
the particle, and the second one is for updating the influencer itself, as
shown in the following code:
public void influenceRealtime(Particle particle,
float tpf);
public void update(float tpf);
2. In our
BirdParticleInfluencer
class, we're going to need some
new fields. The
maxImages
property keeps track of how many images
there are in a cycle. The
animationFps
property defines how fast the