Building a particle system
Before we start coding, it will be helpful to see exactly what it is that we are trying to achieve.
Take a look at the following diagram:
The previous illustration is a screenshot of the particle effect on a plain background. We will use this effect in our game. We will spawn one of these effects each time the player dies.
The way we achieve this effect is as follows:
- First, we spawn 1,000 dots (particles), one on top of the other, at a chosen pixel position.
- Each frame of the game moves each of the 1,000 particles outwards at a predetermined but random speed and angle.
- Repeat step two for two seconds and then make the particles disappear.
We will use a VertexArray
to draw all the dots and the primitive type of Point
to represent each particle visually. Furthermore, we will inherit from the SFML Drawable
class so that our particle system can take care of drawing itself.