Generating ParticleMesh faster?

In my game, there will be approximately 18 attacks which will all use ParticleMesh. Originally, I wanted these to be instant-cast. When I create them on-click, however, even my beast of a computer lags to create the objects. Should I just create the objects and keep cooldowns so people can't cast more often than they are spawned, use spell-cast bars, or is there a way to optimize this?

Do you create new instances of ParticleMesh on the fly?

You want to create a pool of like 10 ParticleMesh and then re-use them.



http://www.jmonkeyengine.com/jmeforum/index.php?topic=5869.0

I wanted to create them on the fly so I could have as many spells in the world at once as I wanted… so you're suggesting instead of just destroying the objects that I keep them in an array list and just reset their position or something?

yep. decide how many effect should be visible at a time and create a pool that big.



When you need to cast a spell, grab a inactive particlemesh from the pool and set the correct location and respawn.

If all effects are busy and you still want to create a new one, you can create a new particleMesh and add it into the pool. That way the pool inreases if needed.



You can also look at the particleFactory i use in stardust, i created separate pool's for explosions / missile trails etc.

http://code.google.com/p/jme-demos/source/browse/trunk/stardust/src/com/jmedemos/stardust/effects/ParticleEffectFactory.java

I just implemented this system today and it works like a charm. Thaks for the tip!