回答
我不知道任何水濺模擬算法,所以我會做我的想法,但你將不得不修改,以使其看起來真實。
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);
謝謝瓊生病了! PNG應該也應該是一滴水,或者應該如何? – 2012-01-10 21:44:10
是的,只是一個水滴。 – Jong 2012-01-11 16:04:52
不錯的解決方案。只是注意到ParticleSystem max/minRate是倒置的。與AlphaModifier的參數一樣。對於GLES2,初始化類具有中綴粒子。我希望它有幫助,歡呼。 – 2012-03-06 13:31:06
- 1. 粒子系統
- 2. SFML.NET粒子系統
- 3. 粒子系統libGDX
- 4. 粒子系統DontDestroyOnLoad
- 5. AndEngine粒子碰撞
- 6. 統一3d - 粒子系統
- 7. 粒子系統:粒子生成
- 8. SFML粒子系統架構
- 9. 粒子系統錯誤
- 10. 如何給粒子系統
- 11. C++粒子系統Allegro 5
- 12. XNA粒子系統性能
- 13. 粒子系統設計?
- 14. OpenGL的粒子系統
- 15. 自定義粒子系統
- 16. libGdx中的粒子系統
- 17. OGRE - 創建粒子系統
- 18. 如何使用粒子對象優化畫布粒子系統
- 19. 使用獲取/設置粒子來實例化粒子系統
- 20. 粒子系統中的粒子表現怪異
- 21. Unity粒子系統到精靈表
- 22. 如何獲得粒子系統之一?
- 23. cocos2d粒子系統自動刪除
- 24. 帶Open GL ES的UIKit粒子系統?
- 25. 粒子系統無法播放()
- 26. Cocos2d/Cocos2d-x粒子系統暫停
- 27. unity3d打開關閉粒子系統
- 28. 如何使粒子系統可點擊
- 29. 如何停止粒子系統
- 30. 2d中的粒子系統入門
http://gamedev.stackexchange.com/可能是一個更好的選擇? – TryTryAgain 2012-01-10 15:09:55
謝謝,生病的地方也有。看起來我們有更多的用戶在這裏幫忙。 – 2012-01-10 15:10:45
誠然,這裏有更多的流量。不確定雙張貼或甚至鏈接將是要走的路。我會看到它是如何在這裏發生的,然後在SO上沒有任何事情發生時將它遷移。 – TryTryAgain 2012-01-10 15:11:40