首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AndEngine粒子系统

AndEngine粒子系统
EN

Stack Overflow用户
提问于 2012-01-10 23:08:09
回答 1查看 5K关注 0票数 2

我想使用AndEngine的粒子系统来创建飞溅(就像在飞溅的水中)。

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

你有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-11 03:14:13

我不知道任何水花模拟算法,所以我会做我认为,但您将不得不修改,使其看起来真实。

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

试试这个:

代码语言:javascript
运行
复制
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后,只需将其附加到场景:

代码语言:javascript
运行
复制
final ParticleSystem particleSystem = createParticleSystem(...);
scene.attachChild(particleSystem);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8805441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档