题
我想使用和发动机的粒子系统创建飞溅(如在溅水中)。
我已经检查了粒子系统示例,但不确定要使用粒子系统创建水的溅起影响需要做什么。
有任何想法吗?
解决方案
我不知道有任何水飞溅模拟算法,所以我会做我的想法,但是您必须修改才能使其看起来真实。
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);
不隶属于 StackOverflow