Efficient way to make sprite based particle effect?

I have had many issues with trying to control particle effect numbers with the concealment system I’m using for the game I’m working on. I want to have animated fog which conceals tiles precisely until certain events trigger removal. I.e. in the level in the below screenshot flipping the lever at the very top of the screen triggers some fog removal and spawning of enemies in that zone for the player to fight. The particle fx fog runs much better, but I can’t accurately control things that are required to use it (how fast it dissipates, how many particles are created (when the level respawns and the particles are clearing out from the last run of the level, the new particle effects stack on top and double the number of effective particles w/ no way to instantly clear them), and the shaders I’m using have some issues occasionally with particle effects where sprites are handled fine.

All that being said, I’m wondering if there’s a way to pre-render a large number of sprite animations into a buffer and then just loop the buffer and then perhaps swap it out for another buffer (such as a fade out animation set) when an event fires. Right now I’m creating 1 fog sprite per tile, and moving them in random x/y directions in order to create an animated foggy effect (which looks pretty cool, but I also want to add some shaders to improve it.) However, this would probably tank the performance without some optimizations. Anyone have some experience with this type of performance challenge?

Are you sure it would tank performance? How many game objects with sprites are we talking about?

From my testing outside of debug it seems to run fine, however in debug mode the game runs noticeably slower with the particles added. The levels I’ve tested on have ~1000-2000 of them. Each of them has animations on the x/y position playing. I’m starting to feel that particle systems are better for ambient effects, not gameplay informational effects. Do you know how difficult it would be to implement some additional particle system functionality? I still have yet to build Defold, but I’d be interested in helping improve that area if possible since I do feel the current system could use some additional improvement. For example, instantly clearing a particle system (clear vs stop function) and prioritization of particle systems somehow.

You mean when you do Debug->Start/Attach or when you bundle with variant set to Debug?

Nothing is easy when it comes to game engines :slight_smile: But it’s pretty straight forward code that should be easy to understand if you are comfortable with C. Keep in mind though that there are many moving parts that are all interconnected and changing one usually means changing the rest as well:

  • The particle system
  • The Lua API
  • The dataformat
  • The editor
  • The documentation
1 Like