Hi all!
Can I change the number of emitted particles/ses without emitting all particles first?
Every time I call setParticlesPerSec() the emitter emits all particles before starting to emit with the new settings.
Thanks
NagPer
Please write a test case and show us the code. I have not seen this behavior but maybe I do something different than you do.
Eh… sorry. During creating the test case I’ve found a bug in my code… so it solves the problem
Although there is another strange thing but I want to investigate it before asking any further questions.
Thanks anyway.
Well… I can’t figure it out what’s happening.
Here is the test code, please somebody run it and explain it for me.
Why all the particles are appearing at once after changing the particles/sec from zero to 16?
[java]package jme3test.effect;
import com.jme3.app.SimpleApplication;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh.Type;
import com.jme3.material.Material;
public class TestMovingParticle extends SimpleApplication {
private ParticleEmitter emit;
int i=1;
float time;
public static void main(String[] args) {
TestMovingParticle app = new TestMovingParticle();
app.start();
}
@Override
public void simpleInitApp() {
emit = new ParticleEmitter(“Emitter”, Type.Triangle, 300);
emit.setGravity(0, 1, 0);
emit.setParticlesPerSec(1);
emit.setLowLife(5);
emit.setHighLife(5);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Particle.j3md”);
emit.setMaterial(mat);
rootNode.attachChild(emit);
}
@Override
public void simpleUpdate(float tpf) {
time+=tpf;
//increase the number of emitted particles once / 5 seconds
if (time > 5){
i*=2;
// When i=8 I set the particles/sec back to 0 …
if (i==8){
emit.setParticlesPerSec(0);
}
//… otherwise I just increase the particles/sec normally
else {
emit.setParticlesPerSec(i);
}
time = 0;
}
}
}[/java]
Thank a lot!
NagPer
I can can simply reproduce the above “problem” in the scenecomposer by adding an emitter to teh scene and manipulate the “Particles Per Sec” values.
set the gravity or initial velocity to some value to see what’s happening.
set the “Particles Per Sec” value to 0.2
then just BEFORE the next particle would come out of the emitter apply a significantly greater value (10 for example) an see what happens.
I suggest that you do not increase i forever. With the code fixed I just don’t see what you are describing. Maybe because I run on the nigthly builds.
[java] public void simpleUpdate(float tpf) {
time += tpf;
//increase the number of emitted particles once / 5 seconds
if (time > 5) {
i *= 2;
// When i=8 I set the particles/sec back to 0 …
if (i == 8 ) {
i = 1;
}
emit.setParticlesPerSec(i);
time = 0;
}
}
[/java]
Well, your fixed code doesn’t cover the problem what I have indeed.
You never set the particles/sec to 0, so the particles are continuously coming hence my problem show up.
Besides, we don’t need to use i as a parameter at all… it’s just for time calculation; in the code below I just set the parts/sec to 10.
I think if you run the code below it clearly shows what the problem is: you cannot stop the emitting process and start it again later without this strange behavior.
[java] @Override
public void simpleUpdate(float tpf) {
time+=tpf;
//increase the number of emitted particles once / 5 seconds
if (time > 3){
i*=2;
// When i=8 I set the particles/sec back to 0 …
if (i==4){
emit.setParticlesPerSec(0);
}
//… otherwise I just set the particles/sec to 10
else emit.setParticlesPerSec(10);
time = 0;
System.out.println(i);
}
}[/java]
I,ve set the initial value of particles/sec to 10 as well in simpleInitApp() just to make it clearer to see what I am talking about.
[java]emit.setParticlesPerSec(10);[/java]
Yes now I see what you mean, it doesn’t actually emit all particles (there is a method for that - try it and you’ll see it isn’t the effect we are looking at).
This is what I see with your test case:
The particle emitter spawns particles as it should.
When set to 0 there are no more particles spawned, the existing ones are updated until they die.
When set back to X, the particles that have not had time to die are strangely “resurrected” and sort of gets their lifespan extend.
I also think this is not the expected behavior. The reason I have not seen this is probably because when I use particle emitters (I do almost exactly the same thing you do) my particles have had time to die before changing back the emitter rate.
I’ll try to understand the code @Momoko_Fan has written and see if I can pinpoint this but you can also have a look at the source, it is open after all
Thanks jmaasing… I hope it might will be fixed soon, I’ll try to check the source as well, but I’am not so advanced in JME’s source to be able to fix it.
Yes, I know it is not the emailAllParticles… my first problem corresponded to a different problem what caused by a bug in my code.
I think I found the problem and what I think is a patch to solve it: http://hub.jmonkeyengine.org/groups/contribution-depot-jme3/forum/topic/patch-particleemitter-particlespersecond-set-to-0-accumulates-timediff/