Andengine粒子碰撞效果(Android游戏开发)

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)

谁能提供一些指导?提前致谢!

Pla*_*eon 6

您在上面的代码中有基础知识.以下是如何做你想要的:

  1. 创建一个particleEmitter
  2. 创建一个粒子系统
  3. 添加修饰符和初始值设定项,为粒子提供所需的行为.

现在秘诀是:

  1. 停止你的粒子系统: particleSystem.setParticlesSpawnEnabled(false);

  2. 在碰撞时,使用以下方法将粒子发射器移动到应发射粒子的位置: particleEmitter.setCenter(xPosition , yPosition);

  3. 当产生粒子的时间结束时,启动TimerHandler以关闭粒子.TimerHandler是一个Andengine类,它像处理程序一样工作,但暂停和恢复游戏.

那应该做啊!