EffectTrack now disable and cull the emitter once all particles are gone
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9625 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
2ab5e4abbe
commit
ef98888ce7
@ -36,6 +36,12 @@ import com.jme3.export.InputCapsule;
|
||||
import com.jme3.export.JmeExporter;
|
||||
import com.jme3.export.JmeImporter;
|
||||
import com.jme3.export.OutputCapsule;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.Spatial.CullHint;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import com.jme3.scene.control.Control;
|
||||
import com.jme3.util.TempVars;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -64,19 +70,45 @@ public class EffectTrack implements Track {
|
||||
private float length = 0;
|
||||
private boolean emitted = false;
|
||||
private boolean initialized = false;
|
||||
private boolean stopRequested = false;
|
||||
|
||||
//control responsible for disable and cull the emitter once all particles are gone
|
||||
private AbstractControl killParticles = new AbstractControl() {
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
if (emitter.getNumVisibleParticles() == 0) {
|
||||
emitter.setCullHint(CullHint.Always);
|
||||
emitter.setEnabled(false);
|
||||
emitter.removeControl(killParticles);
|
||||
stopRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
}
|
||||
|
||||
public Control cloneForSpatial(Spatial spatial) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
//Anim listener that stops the Emmitter when the animation is finished or changed.
|
||||
private class OnEndListener implements AnimEventListener {
|
||||
|
||||
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
|
||||
if(!stopRequested){
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
|
||||
if(!stopRequested){
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* default constructor only for serialization
|
||||
@ -84,7 +116,6 @@ public class EffectTrack implements Track {
|
||||
public EffectTrack() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and EffectTrack
|
||||
* @param emitter the emmitter of the track
|
||||
@ -125,9 +156,14 @@ public class EffectTrack implements Track {
|
||||
//checking fo time to trigger the effect
|
||||
if (!emitted && time >= startOffset) {
|
||||
emitted = true;
|
||||
stopRequested = false;
|
||||
emitter.setCullHint(CullHint.Dynamic);
|
||||
emitter.setEnabled(true);
|
||||
//if the emitter has 0 particles per seconds emmit all particles in one shot
|
||||
if (particlesPerSeconds == 0) {
|
||||
emitter.emitAllParticles();
|
||||
emitter.addControl(killParticles);
|
||||
stopRequested = true;
|
||||
} else {
|
||||
//else reset its former particlePerSec value to let it emmit.
|
||||
emitter.setParticlesPerSec(particlesPerSeconds);
|
||||
@ -139,6 +175,8 @@ public class EffectTrack implements Track {
|
||||
private void stop() {
|
||||
emitter.setParticlesPerSec(0);
|
||||
emitted = false;
|
||||
emitter.addControl(killParticles);
|
||||
stopRequested = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,8 +255,4 @@ public class EffectTrack implements Track {
|
||||
length = in.readFloat("length", length);
|
||||
startOffset = in.readFloat("startOffset", 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user