In the first step, we need to set up an ITextureRegion object to supply our particle system.
The ITextureRegion object will visually represent each individual particle that spawns.
The texture region can be of any size, but typically they will be between 2 x 2 to 32 x 32
pixels. Remember that the particle system is meant to spawn a large number of objects,
so the smaller the ITextureRegion object, the better off the performance will be as far
as the particle system goes.
In the second step, we create our particle emitter and center it on the Scene object. The
particle emitter is the component within a particle system that controls where particles will
initially spawn. In this recipe, we are using a PointParticleEmitter object type, which
simply spawns all particles in the exact same coordinates on the scene as defined by the
particleSpawnCenterX and particleSpawnCenterY variables. AndEngine includes
four other particle emitter types which will be discussed shortly.
Once we've got our particle emitter created and set up as we see fit, we can move onto the
third step and create the BatchedSpriteParticleSystem object. The parameters that we
are required to pass to the BatchedSpriteParticleSystem object include, in this order,
the particle emitter, the minimum spawn rate of the particles, the maximum spawn rate, the
maximum number of particles that can be simultaneously displayed, the ITextureRegion
object that the particles should visually represent, and the mEngine object's vertex buffer
object manager.
Finally, in the fourth step we are adding an AccelerationParticleInitializer
object, which will provide an accelerating movement to the particles so that they're not
simply sitting where they spawn. We are also adding an ExpireParticleInitializer
object, which is used to destroy particles after a defined amount of time. Without some sort
of initializer or modifier removing particles, the BatchedParticleSystem object would
eventually reach its maximum particle limit and discontinue particle spawning. Lastly, we're
adding a ScaleParticleModifier object to the particle system which will change each
particle's scale over time. These particle initializers and particle modifiers will be explained
more in-depth shortly, for now, just know that this is the step where we'd apply them to the
particle system. Once we've added our initializers and modifiers of choice, we attach the
particleSystem object to the Scene object.
After completing these four steps, the particle system will begin to spawn particles. However,
we may not always want the particles to spawn from a specific particle system. To disable
particle spawning, we can make the call, particleSystem.setParticlesSpawnE
nabled(false), or true to re-enable particle spawning. Aside from this method, the
BatchedSpriteParticleSystem object contains all of the ordinary functionality and
methods of an Entity object.
For more information on the individual components of a particle system, see the following
subtopics. These topics include particle emitters, particle initializers, and particle modifiers.