Game Development Reference
In-Depth Information
An advanced ParticleEmitter class
Soaring birds are nice but it's easy to feel that the result of the previous recipe could have
been much better if the birds were better animated. If you've worked with the
ParticleEmitter
class before or have been observant of the birds, you will know that
particles can actually be animated although they only cycle through every frame once per
lifetime. This is much too slow for the birds.
In this recipe, we're going to look at what's needed to make the birds flap their wings. It's
not as simple as it sounds and requires modifying the
ParticleEmitter
code and writ-
ing our own
ParticleInfluencer
class.
If we have a look at the
ParticleEmitter
class to see what we need to do, we can see
that there is an
updateParticle
method that seems like a good place to start. This is
called for every particle in each update cycle. One thing that is less obvious at first is that
since we have the same
ParticleInfluencer
instance affecting all particles, it also
needs to be updated separately for each frame. To achieve the latter, we can use a control.