AndEngine粒子系统

发布于 2024-12-26 03:10:17 字数 103 浏览 0 评论 0原文

我想使用 AndEngine 的粒子系统来创建飞溅(如溅水)。

我已经检查了粒子系统示例,但不太确定需要做什么才能使用粒子系统创建水的飞溅效果。

有什么想法吗?

I would like to use AndEngine's particle system to create a splash(as in splashing water).

I have checked out the particle system example, but not really sure on what needs to be done to create a splash affect of water using the particle system.

Any idea's?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亽野灬性zι浪 2025-01-02 03:10:17

我不知道任何水花模拟算法,所以我会按照我的想法去做,但你必须修改以使其看起来真实。

2D 水花动画会从一个位置创建许多小水滴,然后以初始速度将每个水滴发送到不同的方向,然后每个水滴减慢速度并淡出。

试试这个:

public ParticleSystem createParticleSystem(final TextureRegion waterDropTextureRegion) {
    //X & Y for the particles to spawn at.
    final float particlesXSpawn = 400;
    final float particlesYSpawn = 300;

    //Max & min rate are the maximum particles per second and the minimum particles per second.
    final float maxRate = 10;
    final float minRate = 5;

    //This variable determines the maximum particles in the particle system.
    final int maxParticles = 100;

    //Particle emitter which will set all of the particles at a ertain point when they are initialized.
    final PointParticleEmitter pointParticleEmtitter = new PointParticleEmitter(particlesXSpawn, particlesYSpawn);

    //Creating the particle system.
    final ParticleSystem particleSystem = new ParticleSystem(pointParticleEmtitter, maxRate, minRate, maxParticles, waterDropTextureRegion);

    //And now, lets create the initiallizers and modifiers.
    //Velocity initiallizer - will pick a random velocity from -20 to 20 on the x & y axes. Play around with this value.
    particleSystem.addParticleInitializer(new VelocityInitializer(-20, 20, -20, 20));

    //Acceleration initializer - gives all the particles the earth gravity (so they accelerate down).
    particleSystem.addParticleInitializer(new GravityInitializer());

    //And now, adding an alpha modifier, so particles slowly fade out. This makes a particle go from alpha = 1 to alpha = 0 in 3 seconds, starting exactly when the particle is spawned.
    particleSystem.addParticleModifier(new AlphaModifier(1, 0, 0, 3));

    //Lastly, expire modifier. Make particles die after 3 seconds - their alpha reached 0.
    particleSystem.addParticleModifier(new ExpireModifier(3));  

    return particleSystem;
}

我还没有测试过,但我认为它会起作用。尝试使用这些值来找到看起来逼真的动画。

该方法接收一个参数,该参数是每个粒子的就绪纹理区域,在您的情况下,我猜那是一个水滴。

调用此方法并获取 ParticleSystem 后,只需将其附加到您的场景即可:

final ParticleSystem particleSystem = createParticleSystem(...);
scene.attachChild(particleSystem);

I don't know of any water splash simulation algorithms, so I'll do what I think, but you will have to modify to make it look real.

Water splash animation in 2D will create many small water drops from a single location, then send each one in a different direction with an initial velocity, then each water drop slows down and fades out.

Try this out:

public ParticleSystem createParticleSystem(final TextureRegion waterDropTextureRegion) {
    //X & Y for the particles to spawn at.
    final float particlesXSpawn = 400;
    final float particlesYSpawn = 300;

    //Max & min rate are the maximum particles per second and the minimum particles per second.
    final float maxRate = 10;
    final float minRate = 5;

    //This variable determines the maximum particles in the particle system.
    final int maxParticles = 100;

    //Particle emitter which will set all of the particles at a ertain point when they are initialized.
    final PointParticleEmitter pointParticleEmtitter = new PointParticleEmitter(particlesXSpawn, particlesYSpawn);

    //Creating the particle system.
    final ParticleSystem particleSystem = new ParticleSystem(pointParticleEmtitter, maxRate, minRate, maxParticles, waterDropTextureRegion);

    //And now, lets create the initiallizers and modifiers.
    //Velocity initiallizer - will pick a random velocity from -20 to 20 on the x & y axes. Play around with this value.
    particleSystem.addParticleInitializer(new VelocityInitializer(-20, 20, -20, 20));

    //Acceleration initializer - gives all the particles the earth gravity (so they accelerate down).
    particleSystem.addParticleInitializer(new GravityInitializer());

    //And now, adding an alpha modifier, so particles slowly fade out. This makes a particle go from alpha = 1 to alpha = 0 in 3 seconds, starting exactly when the particle is spawned.
    particleSystem.addParticleModifier(new AlphaModifier(1, 0, 0, 3));

    //Lastly, expire modifier. Make particles die after 3 seconds - their alpha reached 0.
    particleSystem.addParticleModifier(new ExpireModifier(3));  

    return particleSystem;
}

I haven't tested it, but I think it'd work. Try playing with the values to find an animation which looks reallistic.

The method receives an argument which is a ready texture region for each particle, in your case I guess that'd be a water drop.

After you call this method and get a ParticleSystem, just attach it to your scene:

final ParticleSystem particleSystem = createParticleSystem(...);
scene.attachChild(particleSystem);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文