2012-02-05 9 views
1

私は.createCollisionEffect(pos x, pos y, float duration);Andengine粒子衝突の影響(アンドロイドゲームのDev)

のようなものを呼び出すことができ、エンジンが指定された期間のために、粒子のランダムな方向拍車を作成するパーティクルエンジンの開発に興味を持っています。私は、次のコードを見つけましたが、それはランダムに1を選択したので、私はしかし、私は時間と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

ちょうど明確にする:あなたはオブジェクトと衝突する粒子を作ろうとしていませんよね?衝突が発生したときに起こるパーティクルエフェクトを作成しています。それはあなたがしようとしていることですか? –

+0

ええ、あなたはそれを正確に得た! – Aziz

答えて

6

上記のコードには基本があります。ここでは、あなたが探しているものを行う方法である:

  1. パーティクルシステムを作成しますparticleEmitter
  2. を作成し、あなたの粒子あなたが望む行動を与えること修飾子と初期化子を追加します。

そして今、秘密のソース:、衝突オンparticleSystem.setParticlesSpawnEnabled(false);

  • を、それが使用して粒子を放出しなければならない、あなたのパーティクルエミッタを移動:

    1. あなたのパーティクルシステムを停止particleEmitter.setCenter(xPosition , yPosition);

    2. パーティクルを生成する時間が終了したら、TimerHandlerを起動してパーティクルをシャットオフします。 TimerHandlerはハンドリングのように動作するAndengineクラスですが、一時停止してゲームを再開します。

    これでよろしいですか!

  • +1

    私はTimerHandlersや良いリソースへのリンクの例を教えていただけますか? – Aziz

    +1

    ここで私はそれを拾いました: http://stackoverflow.com/questions/8271473/how-to-change-timerhandler-delay-in-andengine 私は元の質問によって掲載されたコードをお勧めします。できます。 –

    +0

    また、このチュートリアルでは、TimerHanderを使用するエンジンゲームを作成します。 https://jimmaru.wordpress.com/2011/09/28/andengine-simple-android-game-tutorial/ –