pixijs / particle-emitter

A particle system for PixiJS
http://pixijs.io/particle-emitter/docs
MIT License
796 stars 125 forks source link

How do I exit the "update" script? #139

Closed shigimcp closed 3 years ago

shigimcp commented 3 years ago

Hi!

I'm a bit of a noob, so I'm not even sure if I'm using the right approach here (even though I'm getting exactly what I'm looking for visually)...

You can check out the demo here: https://shigimcp.github.io/gsap2020/

You can check out the code here: https://github.com/shigimcp/gsap2020/blob/master/src/banners/CR_10263_J_by_JENNIFER_ANISTON_Kohls_300x250/JBJA_10263.jsx

My problem:

Question: - How do I exit the "update" script after the particle animation is done, i.e. emitterLifetime has expired?

Thanks for any help/guidance you guys can provide!

andrewstart commented 3 years ago

Instead of emitter.emit = true, you would want to use emitter.playOnce(() => { /* do cleanup */ }). Alternatively, you could use emitter.playOnceAndDestroy(() => { /* do cleanup */}) which would attach the emitter to PixiJS's shared ticker that your PIXI.Application is already using and will destroy the emitter as well once it completes. In both cases, however, you'd want to destroy the Application when you are done rendering (and possibly remove the canvas from the DOM).

Side note: the animation isn't complete when emitterLifetime has expired - that's just when it stops emitting particles. Both of the methods I mentioned perform the complete callback after all particles have died out, when the animation is truly complete.

shigimcp commented 3 years ago

Falls to ground. Breaks down in tears. THANKYOU!!!THANKYOU!!!THANKYOU!!!

I can't tell you how much time I spent and how many ways I tried to get out of that "update" loop... SMH. Your solution is so simple and so elegant! (Man, what a miss on my part; my NOOB flag is truly flyin' in FULL glory for all to laugh at. LOL!)

And thanks for clarifying emitterLifetime! Everything makes much more sense now.

Skips off into sunset to find more trouble to get into...