Detaching ParticleManagers

In my game right now I have about 5 seperate particle managers which are used for different explosion effects (this will grow to a larger number but I’m just testing things right now).



I used the technique that renase posted in which you set


particleManager.setRepeatType(Controller.RT_CLAMP);



and then call

particleManager.forceRespawn();



to fire the explosion.

Right now when I need an effect I ask the effectManager for an idle effect and then I attach it to the scene. I never detach the effect from the scene. I assume if you try to attach something to the scene that's already attached then it will detach itself from what it's currently attached to first. (this seems to be how it is working now).

To keep the triangle count to a minimum I would like to detach particles from the scenegraph if they are not in use.

At the moment it seems like the only way to do this is to poll each particleManager every frame to check if the particles are alive. If they are not alive then detach the particles from the scenegraph.

Assuming this is the only way to do it, then I think it would be much better if there was some way to register an observer with the particle system that would fire an event when the particle system ceased to be alive. This would keep you from having to loop through all your effects every frame checking which ones should be detached.

So my question is two fold. Is there a more efficient way to do what I want to do without changing current jME code? If not, does the observer idea sound feasible? Thanks for your help and input!

I actually do this in my explosion manager:


    public static void cleanExplosions() {
        int count = 0;
        for (int x = 0, tSize = explosions.size(); x < tSize; x++) {
            ParticleManager e = (ParticleManager)explosions.get(x);
            if (!e.isActive()) {
                if (e.getParticles().getParent() != null)
                    e.getParticles().removeFromParent();
                count++;
                if (count > 5) {
                    explosions.remove(x);
                    tSize--;
                }
            }
        }
    }



It's an observer of sorts.... :) 5 is how many I leave in my cache no matter what.

You call the cleanExplosions method every update right?





If so then it looks like what I was planning to do which is good to know

:smiley: