Hi all,
I needed a quick way to add many explosions to my system. So ive added a few methods in ParticleSystem to clone it quickly:
// how many times the manager has warmed up
private int iterations;
/**
*
* Return the number this manager has warmed
* up
* @return int
*/
public int getIterations() {
return iterations;
}
/**
* Runs the update method of this particle manager for iteration seconds
* with an update every .1 seconds (IE <code>iterations</code> * 10
* update(.1f) calls). This is used to "warm up" and get the particle
* manager going.
*
* @param iterations The number of iterations to warm up.
*/
public void warmUp(int iterations) {
this.iterations = iterations;
for (int i = iterations; --i>= 0; )
update(.1f);
}
/**
* Sets the iterations for the warmup and calls
* warmUp with the number of iterations as the argument
* @param iterations
*/
public void setIterations(int iterations) {
warmUp(iterations);
}
And for the most important part:
/**
* Clones every aspect of this manager into a new manager
*/
public Object clone() {
ParticleManager manager = new ParticleManager(getParticlesNumber(),
getCamera());
manager.setControlFlow(getControlFlow());
manager.setEmissionDirection((Vector3f) getEmissionDirection().clone());
manager.setEmissionMaximumAngle(getEmissionMaximumAngle());
manager.setEndColor((ColorRGBA) getEndColor().clone());
manager.setEndSize(getEndSize());
manager.setGeometry(getGeoMesh());
manager.setGeometry(getGeometry());
manager.setGravityForce((Vector3f) getGravityForce().clone());
manager.setInitialVelocity(getInitialVelocity());
manager.setParticlesMinimumLifeTime(getParticlesMinimumLifeTime());
manager.setParticlesOrigin((Vector3f) getParticlesOrigin().clone());
manager.setParticleSpinSpeed(getParticleSpinSpeed());
manager.setPrecision(getPrecision());
manager.setRandomMod(getRandomMod());
manager.setReleaseRate(getReleaseRate());
manager.setReleaseVariance(getReleaseVariance());
manager.setSpeed(getSpeed());
manager.setStartColor((ColorRGBA) getStartColor().clone());
manager.setStartSize(getStartSize());
manager.setIterations(getIterations());
manager.setRepeatType(this.getRepeatType());
manager.getParticles().addController(manager);
for (int i = 0; i < getParticles().getRenderStateList().length; i++) {
if (getParticles().getRenderStateList()[i] != null) {
manager.getParticles().setRenderState(getParticles()
.getRenderStateList()[i]);
}
}
manager.getParticles().setModelBound(getParticles().getModelBound());
manager.getParticles().updateModelBound();
return manager;
}
What do you think?
Edit: The clone method definetly works now. And the brilliant thing is that you dont have to reload the textures and recreate the alpha states and zBufferStates :D
DP