Hey,
I made some cinematics today and I saw that there are no predefined events for Particle effects. You can’t add for example a fire effect after a certain time. So I wrote these two classes:
[java]
package mygame;
import com.jme3.cinematic.events.AbstractCinematicEvent;
import com.jme3.effect.ParticleEmitter;
import com.jme3.scene.Node;
/**
*
-
@author mathiasj
*/
public class EmitAllEffectEvent extends AbstractCinematicEvent {private ParticleEmitter pe;
private boolean emitted;
private boolean paused;public EmitAllEffectEvent(ParticleEmitter particleEmitter, Node effectNode) {
pe = particleEmitter;
effectNode.attachChild(pe);
}@Override
public void onPlay() {
if(paused) {
pe.setEnabled(true);
paused = false;
}
if (emitted) {
return;
}
pe.emitAllParticles();
emitted = true;
}@Override
public void onStop() {
pe.killAllParticles();
emitted = false;
}@Override
public void onPause() {
pe.setEnabled(false);
paused = true;
}@Override
public void onUpdate(float tpf) {
}
}
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package mygame;
import com.jme3.cinematic.events.AbstractCinematicEvent;
import com.jme3.effect.ParticleEmitter;
import com.jme3.scene.Node;
/**
*
-
@author mathiasj
*/
public class EffectEvent extends AbstractCinematicEvent {private ParticleEmitter pe;
private boolean paused;
private boolean attached;
private Node effectNode;public EffectEvent(ParticleEmitter particleEmitter, Node effectNode, float duration) {
super(duration);
pe = particleEmitter;
this.effectNode = effectNode;
}@Override
public void onPlay() {
if (paused) {
pe.setEnabled(true);
paused = false;
return;
}
if (attached) {
return;
}
effectNode.attachChild(pe);
attached = true;
}@Override
public void onStop() {
effectNode.detachChild(pe);
attached = false;
}@Override
public void onPause() {
pe.setEnabled(false);
paused = true;
}@Override
public void onUpdate(float tpf) {
}
}
[/java]
EffectEvent is an Event for a normal ParticleEmitter and it will start emitting its particles once it is reached in the timeline of the Cinematic. The EmitAllEffectEvent is for Particle Emitters that, as the name says, just emit all particles at once. They will not be played continously, but they will emit all their particles once when they are reached in the timeline.
Note: You must not attach the ParticleEmitters manually, but you can of course define the LocalTranslation of it.
Here is a Video showing it:
[video]- YouTube