14

Can anyone give me a good example of where to start with making a particle system in libGDX? I have looked at the test example in the libGDX source but I am still having trouble getting my head around it. Maybe just a good explanation of it will help. I'm thinking I want to make some sort of explosion with a lot of colorful particles. Any help is greatly appreciated!

Alex_Hyzer_Kenoyer
  • 1,321
  • 4
  • 17
  • 23

2 Answers2

29

Define a particle effect in your game class:

public ParticleEffect particleEffect;

Initialize it:

    particleEffect = new ParticleEffect();
    particleEffect.load(Gdx.files.internal("data/particleEffect.p"), 
            Gdx.files.internal("data"));

In your render() method, position it at the place you want particles to be emitted (explosion location):

    particleEffect.setPosition(world.effectX, world.effectY);

And draw it finally (also within render()):

    particleEffect.draw(spriteBatch, delta);

That's it, pretty simple and straightforward.

Another thing, the effect itself, have a look at the Particle Editor by Nate, http://libgdx.googlecode.com/svn/jws/particle-editor.jnlp. Using the editor you should be able to create nice effects. Otherwise, copy the particle file from the examples and modify it.

Dominik Bucher
  • 1,509
  • 13
  • 16
  • Thanks a lot, this is exactly what I was looking for. A nice, simple example, and explanation... Is the particle editor working for you? I wasn't able to get it to open, any ideas? Thanks again! – Alex_Hyzer_Kenoyer Mar 05 '12 at 21:11
  • 4
    You will also need to call `particleEffect.start();` to actually begin the particle system. – DRiFTy Mar 06 '12 at 01:25
  • 2
    In my setup `.start()` isn't necessary... strange, probably it's called somewhere in the particleEffect's init. As for the editor, I'm not quite sure why, but it only runs if I download it into my default download folder and start it from within the browser. Probably due to some Java Web Start security policies... – Dominik Bucher Mar 06 '12 at 19:21
  • 2
    I think `start()` is only needed when your effect isn't continuous. The continuous effects seem to run on their own from what I see. What I would do about the `ParticleEditor` is just build it from the source in SVN. That's what I do and it works great. – DRiFTy Mar 08 '12 at 13:07
  • What is "Gdx.files.internal("data"));" ? – Herb Meehan Apr 28 '15 at 01:52
  • If you look at the definition of `load()` it says: `load(FileHandle effectFile, FileHandle imagesDir)`, so we're just specifying the directory / folder where the images can be found (i.e., the ones rendered as particles). – Dominik Bucher Apr 28 '15 at 07:29
3

Sort of docs in this blog post: http://www.badlogicgames.com/wordpress/?p=1255 Blog post was copy pasted to the wiki: https://code.google.com/p/libgdx/wiki/ParticleEditor When real docs are written in the future, they will be there.

Also, run it from source for the latest, as the JWS is a pain to update.

Now a video: http://www.badlogicgames.com/wordpress/?p=2462

NateS
  • 5,751
  • 4
  • 49
  • 59