2D Particle System using SDL
I am Xavi Marín Solà, student of the Bachelor’s Degree in Video Games by UPC at CITM. This content is generated for the second year’s subject Project 2, under supervision of lecturer Ricard Pillosu.
A particle system is a collection of many many minute particles that together represent a fuzzy object. Over a period of time, particles are generated into a system, move and change from within the system, and die from the system.
Since the early 1980s, particle systems have been used in countless videogames, animations, digital art pieces, and installations to model various irregular types of natural phenomena, such as fire, smoke, waterfalls, fog, grass, bubbles, and so on.
Particle systems are important because they have a notorious visual impact that make the player experience better. Here you can see some examples:
The pool improves performance and memory use by reusing objects from a fixed pool instead of allocating and freeing them individually.
The emitter task is to create particles with the characteristics we define.
Is simply a rendered sprite that when changing its properties simulates the effects we desire.
These properties are:
In general terms, is in charge of controlling everything of the system.
The implementation of this particle system is based on this schema, so I’m going to explain the performance of the system from right to left because is the easiest way to understand how it works.
Every particle has some properties that we must change in order to obtain a particular behaviour. These are the properties:
In order to create particles in the pool we need to ease the values of these particle properties, so that’s why we need this function that will be called in the j1Pool class
To avoid memory fragmentation we use this class. In games, it’s very important to have a good management of memory, that’s why is not a good idea to allocate and free individually each particle.
So, a pool class is the solution because we are able to reuse particles. To implement it we must declare an array of particles and the first particle of this mentioned array
When we have declared the array and the first particle, we must create them on the constructor
In the update we will check if the particle is alive or not.
If it’s alive, the Update() and Draw() methods of the j1Particle class are called. But if it’s not alive, the first particle will become the first available of the array.
Finally, must exist a function to create particles with the properties we want
Basically creates an new j1Pool on the constructor
And in its Update() method, the container will keep on creating more and more particles with those random values
Manages the functionality of the emitters by loading their data and calling their modules through a list.
It also spawns the emitters you desire
And removes them too
Create the function to interpolate colors
SOLUTION
Create an array of particles, then assign the first position of the array to a declared particle
SOLUTION
Load the data of the emitter depending on the “typeNum” variable
SOLUTION
Use the UpdatePos(pos) to make mouseFire emitter follows the position of your mouse
SOLUTION