粒子系统 libGDX

谁能给我一个很好的例子,说明从哪里开始在 libGDX 中制作粒子系统?我已经查看了 libGDX 源代码中的测试示例,但我仍然无法理解它.也许只是对它的一个很好的解释会有所帮助.我在想我想用很多彩色粒子制作某种爆炸.非常感谢任何帮助!

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!

推荐答案

在你的游戏类中定义一个粒子效果:

Define a particle effect in your game class:

public ParticleEffect particleEffect;

初始化它:

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

在您的 render() 方法中,将其放置在您希望发射粒子的位置(爆炸位置):

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

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

最后绘制(也在render()中):

    particleEffect.draw(spriteBatch, delta);

就是这样,非常简单明了.

That's it, pretty simple and straightforward.

另一件事,效果本身,看看 Nate 的粒子编辑器,http://libgdx.googlecode.com/svn/jws/particle-editor.jnlp.使用编辑器,您应该能够创建漂亮的效果.否则,从示例中复制粒子文件并进行修改.

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.

相关文章