Hi all,
I was rendering clones of an particleManager with the bounds on. And i noticed that when the ParticleManager’s repeat type is clamp, and when it reached the final, it didn’t set Active as false, which could save up on quite alot of computational power.
This is useful to see if all the particles are dead and you want to remove the particles from the scene to save up on those prescious vertices. The following code does it nicely:
Declare the int:
private int deadParticles;
In the constructor:
public ParticleManager(int noParticles, Camera cam) {
camera = cam;
this.noParticles = noParticles;
deadParticles = 0;<-- new here
In the update(float time) method:
int i = 0;
while (i < noParticles) {
if (particles[i].updateAndCheck(timePassed)
&& (!controlFlow || particlesToCreate > 0)) {
if (particles[i].status == Particle.DEAD
&& getRepeatType() == RT_CLAMP) {
deadParticles++;//<-- new here
} else {
Also in update:
particlesGeometry.setVertices(geometryCoordinates);
particlesGeometry.setColors(appearanceColors);
}
if (particlesGeometry.getModelBound() != null) {
particlesGeometry.getModelBound()
.computeFromPoints(particlesGeometry.getVertices());
}
// this if statement is new
if (deadParticles == noParticles && getRepeatType() == Controller.RT_CLAMP) {
setActive(false);
}
}
}
This is very useful for:
private void checkPManagerArray() {
for (int i = 0; i < pManagerArray.size(); i++) {
ParticleManager pM = (ParticleManager) pManagerArray.get(i);
if (pM.isActive() == false) {
rootSceneNode.detachChild(pM.getParticles());
pManagerArray.remove(i);
}
}
}
Enjoy! DP