2012-02-05 59 views
1

我感兴趣的开发粒子引擎,我可以调用类似.createCollisionEffect(pos x, pos y, float duration);Andengine粒子碰撞的影响(安卓游戏开发)

,发动机会造成颗粒的随机定向骨刺指定的时间。我发现下面的代码,但我想用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; 
} 

灿任何人提供一些指导?提前致谢!

+0

只是为了澄清:你不是在试图制造与物体碰撞的粒子,对吧?你正在发生碰撞时发生的粒子效应。那是你正在尝试做什么? – 2012-02-08 19:34:55

+0

是的,你明白了! – Aziz 2012-02-09 04:50:54

回答

6

您在上面的代码中具有基础知识。下面是如何做的,你在找什么:

  1. 创建particleEmitter
  2. 创建粒子系统
  3. 添加改性剂和初始化给你的粒子所需要的行为。

而现在的秘密武器:

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

  2. 在碰撞,移动你的粒子发射器,它应该使用发射粒子:particleEmitter.setCenter(xPosition , yPosition);

  3. 启动TimerHandler以在产生粒子的时间结束时关闭粒子。 TimerHandler是一个像处理程序一样工作的Andengine类,但暂停并继续游戏。

这应该做的!

+1

你可以给我一个TimerHandlers的例子或者一个好资源的链接吗? – Aziz 2012-02-11 00:55:35

+1

这里是我捡起来的地方: http://stackoverflow.com/questions/8271473/how-to-change-timerhandler-delay-in-andengine 我推荐原始问题发布的代码。有用。 – 2012-02-11 01:53:07

+0

另外本教程构建了一个使用TimerHander的andengine游戏。 https://jimmaru.wordpress.com/2011/09/28/andengine-simple-android-game-tutorial/ – 2012-02-11 01:55:10