How to create Particle Effect in libgdx
Libgdx is a cross platform game development framework for Windows, Linux and Android. I have been using Libgdx from last some months and found it a good game development framework. Currently, I am working on my new project where I have created “Particle Effect”, found it really magical. “Particle editor(particle-editor.jnlp)” is the software that allowed for particle effects to be easily designed. I’ve ported it to libgdx, and you can check it out via JWS by clicking this url:
Particle effect basically consists of some images that move around. It creates some pretty stunning results with the few images. They are usually good for fire, explosions, smoke, etc. As you can manipulate life, velocity, rotation, scale, etc and observe in real time.
If you can create effect so easily then why to do difficult programming to create such effects???
Follow some simple steps and create magical effect:
1. The first step to create an effect is to choose an image. The example image is just a simple round gradient. Try with different images to create a wide variety of effects. Different shaped images will often combine for some surprising and sometimes very cool looking results.
Remember, when you configure properties, you actually configure the particle emitter that will create and manage the particles.
Let’s talk in terms of some technical terms:
In code, the emitter is the ParticleEmitter class. A particle effect is made up of one or more emitters, which is managed in the lower right of the particle editor. In code, the effect is represented by the ParticleEffect class, which has a list of Particle Emitters.
Some of the amazing effects which you can create from Particle-editor:
Delay: This emitter will do nothing for many milliseconds, after effect starts. You can use it to synchronize multiple emitters.
Note: Delay property has an “Active” button. You can turn off some properties, this will minimize some of the work at runtime.
Duration: How long the emitter will emit particles. But don’t get confused with, how long particles will live, both are different parameters.
Count: It controls the minimum number of particles that must always exist, and the maximum number of particles that can possibly exist. The minimum is nice for making sure particles are always visible, and the maximum lets the emitter know how much memory to allocate.
Emission: This shows how many particles will be emitted per second.
We can watch the video related to, how to apply the Particle Effect on images or object from the bellow link :
After applying the required effect on the image when we will click the save button then we get the output file kaush(any name we
can use) .
kaush file contain the following text :
– Delay –
– Duration –
– Count –
– Emission –
– Life –
– Life Offset –
– X Offset –
– Y Offset –
– Spawn Shape –
– Spawn Width –
– Spawn Height –
– Scale –
– Velocity –
– Angle –
– Rotation –
– Wind –
– Gravity –
– Tint –
– Transparency –
– Options –
– Image Path –
We can directly use the output File of editor in our gaming world as :
To show these in our game first set up a ParticleEffect and an array of emitters:
In the create method we can load the effect file:
effect = new ParticleEffect();
In the render method we can draw the effect:
//world.waterDropX and world.waterDropY are the co-ordinate of image.
effect.setPosition( world.waterDropX, world.waterDropY);
emitters = newArray(effect.getEmitters());
Finally, you will get the magical Particle effect like:
Hope, you will enjoy it!!