The team at WickeyWare was deliberating about the look of Jetpack Miner recently. The basic look and feel of the game had been accomplished, but it was missing something. A little extra “sparkle” or “polish”. One way to achieve this finishing graphical element is to incorporate particles into your game.
The problem with writing your own particle engine is the heavy toll it takes on your game’s frame rate. You have to ensure that the particles can be emitted and killed efficiently. The problem with buying a particle engine is the price is often high (upwards of ), and doesn’t provide the flexibility in effects that we needed . We needed to code our own particle engine, but it needed to be lightweight enough to not slow down this already massive game.
In the simplest terms, a particle engine needs a couple things. Since we are using the Corona SDK framework (which is written in Lua), a lot of the intricacies of normal home-brewed particle engines are abstracted out (rendering, OpenGL stuff, etc.). Rather, we needed to focus on a clean way to kill and emit particles, a lightweight tick for each particle during the time it’s alive, and a way to make it flexible (that is, we can re-use it for multiple projects and the particles can be shaped to get pretty much any desired behaviour).
The first two points boil down to effective coding practices. Initialization is expensive, so do it only once by initializing a large enough pool of unused particles. Then simply set their properties and give them life to create an effect. After decay, they simply go back to the pool. The tick is compromised of velocity, color and alpha calculations, etc (wihout any memory leaks!). The tricky part is making the particle engine extensible. A good way to do this is have a TON of dot properties that you give to each particle when you init them (xDirection, yDirection, speed, StartRGB, EndRGB, StartSize, EndSize, etc.), and make sure there is no hard numbers around. Base everything off of previous knowledge, so the changes you have to make are minimal.