2012-01-10 267 views
2

我想使用AndEngine的粒子系統創建一個飛濺(如在飛濺的水中)。AndEngine粒子系統

我已經檢查了一下粒子系統的例子,但並不確定需要做什麼來創建使用粒子系統的水濺效果。

任何想法的?

+1

http://gamedev.stackexchange.com/可能是一個更好的選擇? – TryTryAgain 2012-01-10 15:09:55

+0

謝謝,生病的地方也有。看起來我們有更多的用戶在這裏幫忙。 – 2012-01-10 15:10:45

+0

誠然,這裏有更多的流量。不確定雙張貼或甚至鏈接將是要走的路。我會看到它是如何在這裏發生的,然後在SO上沒有任何事情發生時將它遷移。 – TryTryAgain 2012-01-10 15:11:40

回答

3

我不知道任何水濺模擬算法,所以我會做我的想法,但你將不得不修改,以使其看起來真實。

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); 
+0

謝謝瓊生病了! PNG應該也應該是一滴水,或者應該如何? – 2012-01-10 21:44:10

+0

是的,只是一個水滴。 – Jong 2012-01-11 16:04:52

+0

不錯的解決方案。只是注意到ParticleSystem max/minRate是倒置的。與AlphaModifier的參數一樣。對於GLES2,初始化類具有中綴粒子。我希望它有幫助,歡呼。 – 2012-03-06 13:31:06