Closed mspanish closed 7 years ago
Nope. It wasn't until relatively recently that the autoUpdate
setting existed, so you couldn't have fire and forget emitters. It seems like a good thing to add.
Yeah I may have this set up wrong, but I am creating a new emitter each time the child feeds a letter to the fish, as I'm using different particles for the colors. I assume that tinting 1 set of particles would be more costly? If not I suppose I could have 1 emitter that re-fires each time, right? Frankly I haven't quite figure out how to re-fire an existing emitter though :)
You can now see my demo live now on https://readvisually.org - under the hood is still a little scary as I've cleaned nothing up yet, but I'm doing my best to clean everything I put on the stage - I add each emitter to an object and try to get rid of it like this:
if (letter && App.emitters[letter]) {
App.emitters[letter].cleanup();
App.emitters[letter].destroy();
App.emitters[letter] = undefined;
}
You can also see your particles at play in the background stream of bubbles, the burst of bubbles when a child matches the color to the barrel in scene 2, and in the starbursts once they match the shapes to the submarine.
I switched to Greensock for the final scene's rising letters animation because I wanted a bit more control, and was getting a jittery effect for some reason on some letters as the letters rose. It still happens a little using TweenMax but not quite as much as when it was a particle stream.
Tinting one set of particles is free in WebGL, and in the Canvas2d fallback probably about as expensive as making a new emitter.
Restarting an emitter is as simple as setting emit
to true again (it functions as play(), pause(), and isPlaying()). When destroying an emitter, you don't need to call cleanup()
- it does that for you. Calling cleanup()
is for immediately cleaning up an emitter, as setting emit
to false stops emission but lets existing particles die out naturally.
Super thanks I'll make adjustments, my setup did seem a bit disastrous to me.
Version 2.1.5 now has playOnceAndDestroy()
, for anyone that it would be useful for in the future.
Awesome! Thank you Andrew!
Is there any way to tell an emitter to destroy itself once it's done (burst type of situation)?