Particles and sparkles

Hey! you have 5 minutes? That’s what you need to read the whole thing! 

Nowadays, we are so used to see incredible effects in almost every videogame and well known game engines supports complex particle effects. It’s awesome to create, for example, awesome smoke effects in a few steps, but in my case I wanted to study in depth how it works, even if I’m never creating a particle system from scratch again.

For now focusing on the 2D basics will be enough.


A basic particle

A basic particle is nothing more than an object with a little texture or animated sprite, a position, a size and a speed vector as attributes. Each particle is updated in the main loop, what means position, speed or even texture changes. When some particles are combined, they can create effects working together drawing them on the screen after each update.

basic particle example

basic particle example

Every particle has to die

Every effect has to end at some point, or even if it’s still alive, it’ll create more and more particles. If older particles don’t disapear after a while, the game will deal with thousands of them, lowering the game’s performace. To avoid this, every particle has a a life team associated usually called “time to live” or TTL. When a particle’s TTL goes to zero, the particle is removed from the one and only particle manager: the particle engine.


An Engine to rule them all!

A good way to keep a huge amount of particles under control is to create a particle engine. A basic one is nothing more than a collection of particles and some methods who calls the update and draws methods of each stored particle, and of course, cleans all the “dead” particles. Using this design we can store different types of particles and update them with one call at the game main loop.


basic particle engine design example

basic particle engine design example

As much particles as you can handle!

The number of particles for each effect is a good case of study. Most times, having a higher amount of smaller particles is better to create more realistic ones, but other aspects like the texture quality or how realistic is the way each particle moves always improves its results.
In spite of it, having lots of complex effects with thousand particles each one can sound awesome, but each particle is an object with a texture to be updated and drawn over the screen. A poorly optimized particle system may affect the game performance dramatically, so using one million particles with high resolution textures and a complex physics engine to update each one attributes may not be as good as it seems.

counter strike effects comparative over different versions

counter strike effects comparative over different versions

Here ends our first particle’s chapter. If you want to know more about this topic or you like any of our old posts, follow us on twitter or Facebook to stay tuned.

Thanks everyone!


Leave a Reply

Your email address will not be published. Required fields are marked *