How to stop particles after first wave

Hey everyone, I am trying to create a smoke cloud in my space game. The Problem I have is I am not sure of the right way to have the emitter stop re emitting particles after the first wave fades out. The emitter it created in a control that activates the explosion of an object. How can I make the emitter timeout after this object is gone?

1 Like

Just remove it from the scenegraph?
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless theres emotes that hint otherwise or theres an increased use of exclamation marks and all-capital words.

1 Like

Actually… I think they are looking for something a little smoother than that…

Try this when the object is removed:

[java]
emitter.setParticlesPerSec(0);
[/java]

Then check the current particle count in your control loop until none are in your scene:

[java]
if (emitter.getNumVisibleParticles() == 0)
emmiterNode.removeFromParent();
[/java]

This should do what you asked.

@t0neg0d said: Actually... I think they are looking for something a little smoother than that...

Try this when the object is removed:

This should do what you asked.

Whats smoother than removing whats not needed from memory? ^^ Really the particle emitter doesn’t represent heaps of calculated data thats worth to be kept.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless theres emotes that hint otherwise or theres an increased use of exclamation marks and all-capital words.

OK, that looks like good code but I am not sure where to put it. See the emitter gets created in a RigidBodyControl’s collision method. Is there a way to create a control for the particle emitter, what should it extend and implement? Or it could maybe be better yet if I could somehow pause the RigidBodyControl to wait for the emitter to reach a cretan number of particles and then remove the spatial and control… and emitter?

edit: also, the emitter seems to move to a new rock whenever a new rock explodes, what would be the solution to this?

@normen

@enigma101 said: The Problem I have is I am not sure of the right way to have the emitter stop re emitting particles after the first wave fades out.

I was saying that he was looking for a different answer than you gave is all. Smoother = have the emitter stop emitting and then wait til all particles have faded before removing the emitter. This was not the answer you gave… so I don’t see the issue with me answering as well. /boggle

@enigma101
This sorta depends on how you are handling removing the object.

At some point you add the emitter. Is this at the same time you remove the ship?

If so… you’ll need to determine a length of time you would like the emitter to cycle (unless you are emitting all particles at once)
set a flag when you add the emitter
add tpf to a counter until it reaches your limit
once the limit is reached, set the emitter to emit 0 particles per second
after this, check against the visible count until it reaches 0
Then remove the emitter.

There are multiple places you can do this from… however to get it working, just put it in the update loop of you control for now.

@enigma101 said: edit: also, the emitter seems to move to a new rock whenever a new rock explodes, what would be the solution to this?

Hmmm… if you are using individual control that adds and removes an instance of emitter for each rock instance, this shouldn’t happen.

@t0neg0d said: I was saying that he was looking for a different answer than you gave is all. Smoother = have the emitter stop emitting and then wait til all particles have faded before removing the emitter. This was not the answer you gave... so I don't see the issue with me answering as well. /boggle
He was asking for how to keep it from emitting particles after they faded out for the first time.. Also he talked about "object is gone".. idk if my interpretation is so off based on that but anyway the issue and your boggling is mainly on your side as you again took something personal you didn't need to. The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless theres emotes that hint otherwise or theres an increased use of exclamation marks and all-capital words.
@normen said: He was asking for how to keep it from emitting particles after they faded out for the first time.. Also he talked about "object is gone".. idk if my interpretation is so off based on that but anyway the issue and your boggling is mainly on your side as you again took something personal you didn't need to. The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless theres emotes that hint otherwise or theres an increased use of exclamation marks and all-capital words.

I think there must be a language barrier here or something, because I don’t take what you say to me personally. Actually, you’re one of my favorite people here. I must just come across like a bitch when it’s not my intention to do so. Now, if I could just figure out how to come across like SUPER-BITCH when I DO mean to :wink:

@t0neg0d said: I think there must be a language barrier here or something, because I don't take what you say to me personally. Actually, you're one of my favorite people here. I must just come across like a bitch when it's not my intention to do so. Now, if I could just figure out how to come across like SUPER-BITCH when I DO mean to ;)
I guess so, I was taking this impression from this bit here:
@t0neg0d said:so I don't see the issue with me answering as well. /boggle
You don't sound especially bitchy to me, no. A bit confused and obsessed sometimes maybe ;) The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless theres emotes that hint otherwise or theres an increased use of exclamation marks and all-capital words.

Thanks guys, i got it removed fron within the original controls update loop. Not sure about the instancing of the particle emitter though, I still can only have one instance of it, aka one effect at a time, even if I explode two things.

@enigma101 said: Thanks guys, i got it removed fron within the original controls update loop. Not sure about the instancing of the particle emitter though, I still can only have one instance of it, aka one effect at a time, even if I explode two things.

How do you create the multiple ones? Do you just pass the same one around or do you do new ParticleEmitter() at some point? The second is the right way and shouldn’t have sharing issues. The first way will definitely have the issues you describe.

Just to put this out there, I created an interface called “Update” with a method called “public boolean update(float tpf).” (I return false to continue updating, true to remove from update stack). In order to constantly update a class I implement Update, and call Main.addUpdate(this); I created my own class for each particle effect I have (bullet hitting a wall, etc.) and implemented this. Then, when there’s no more visible particles I call killAllParticles() and then removeFromParent(); This is also pretty useful for anything you want to control, but that you can’t easily fit into an AbstractControl class.

The update method for my particle class is something like:

[java]
public boolean update(float tpf) {
if (getNumVisibleParticles() == 0) {
killAllParticles();
removeFromParent();
return true;
}
return false;
}
[/java]

1 Like