Azi*_*ziz 1 android particle-system andengine
我有兴趣开发一个我可以称之为的粒子引擎 .createCollisionEffect(pos x, pos y, float duration);
并且引擎将在指定的持续时间内创建随机方向的粒子杂散.我发现以下代码,但我想使用3种不同的纹理,所以它随机选择一个,但我不知道如何管理时间和3种不同的纹理:我发现以下代码:
public ParticleSystem createParticleSystem(final TextureRegion textureRegion) {
//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, textureRegion);
//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((IParticleModifier) new AlphaModifier(3, 1, 0));
//Lastly, expire modifier. Make particles die after 3 seconds - their alpha reached 0.
particleSystem.addParticleModifier(new ExpireModifier(3));
return particleSystem;
}
Run Code Online (Sandbox Code Playgroud)
谁能提供一些指导?提前致谢!
您在上面的代码中有基础知识.以下是如何做你想要的:
现在秘诀是:
停止你的粒子系统: particleSystem.setParticlesSpawnEnabled(false);
在碰撞时,使用以下方法将粒子发射器移动到应发射粒子的位置: particleEmitter.setCenter(xPosition , yPosition);
当产生粒子的时间结束时,启动TimerHandler以关闭粒子.TimerHandler是一个Andengine类,它像处理程序一样工作,但暂停和恢复游戏.
那应该做啊!
| 归档时间: |
|
| 查看次数: |
2437 次 |
| 最近记录: |