Best way to make re-usable particle effects?

23 views
Skip to first unread message

Jacob Vann

unread,
Feb 16, 2015, 6:08:08 PM2/16/15
to haxef...@googlegroups.com
I'm starting to add particle effects to my HaxeFlixel project.  Right now, I'm just adding the code to create the emitters and particles to the object that users them.  So, if I have a "bullet" class that needs to have a trail particle effect or an explosion particle effect, I'm adding all that to the bullet class, and killing/reviving the particle effect as needed.  I'm sure this is not the best way to do it, but wanted to ask you guys for ideas.

Is there a way to add a global particle-effect resource class, similar to the FlxG.sound class, so that I can register and assign particle effects by name, and then just call the particle effect as needed, with something like:

FlxG.particleEffects.play("explosion", x, y);

Has anyone had luck implementing something similar?  The good thing about separating management of particle effects into their own class is you can add a plug-in to load particle effect definitions from a text file so you can tweak your particle effects in a third party tool and then re-run the game without having to recompile. 

And, if I implemented something like FlxG.particleEffects myself, how would I handle playing the same particle effect more than once?  I'm assuming the play() function would actually clone a new instance of the emitter and all the particles, and then destroy it when the effect is done?

I guess I'm looking for suggestions to better manage dozens of particle effects without having all the code for creating those effects scattered throughout my code base.

Thanks!
Reply all
Reply to author
Forward
0 new messages