A particle system for visual effects and environmental elements. More...
#include <SDL.h>#include <vec2.h>#include <stdbool.h>#include <timer.h>#include <camera.h>#include <colliders.h>Go to the source code of this file.
Classes | |
| struct | Particle |
| A struct that represents a particle. More... | |
| struct | ParticleEmitter |
| A struct that represents the configurations of a particle emitter. More... | |
Typedefs | |
| typedef struct Particle | Particle |
| A struct that represents a particle. | |
| typedef struct ParticleEmitter | ParticleEmitter |
| A struct that represents the configurations of a particle emitter. | |
Functions | |
| void | ParticleEmitter_SetMaxParticles (ParticleEmitter *emitter, int maxParticles) |
| Sets the maximum number of particles for an emitter. | |
| void | ParticleEmitter_Emit (ParticleEmitter *emitter) |
| Emits particles from the emitter. | |
| int | ParticleEmitter_GetNextReady (ParticleEmitter *emitter) |
| Gets the next available particle index. | |
| void | ParticleEmitter_UpdateParticles (ParticleEmitter *emitter) |
| Updates the particles of an emitter. | |
| void | ParticleEmitter_Update (ParticleEmitter *emitter) |
| Updates the emitter. | |
| void | ParticleEmitter_ActivateOnce (ParticleEmitter *emitter) |
| Activates the emitter once. | |
| void | ParticleEmitter_Deactivate (ParticleEmitter *emitter) |
| Deactivates the emitter. | |
| void | ParticleEmitter_Render (ParticleEmitter *emitter) |
| Renders the particles of an emitter. | |
| void | ParticleEmitter_DestroyEmitter (ParticleEmitter *emitter) |
| Destroys the emitter and frees its memory. | |
| bool | ParticleEmitter_ParticlesAlive (ParticleEmitter *emitter) |
| Checks if the emitter has any particles alive. | |
A particle system for visual effects and environmental elements.
Particles are emitted from structs called ParticleEmitters.
Therefore, to generate particles, you have to, of course, create a Particle Emitter first. Emitters can be created based on a preset in particle_emitterpresets.c (Information on how to create a preset can be found inside particle_emitterpresets.h) After that, you can update and render the particles inside the game loop.
This is how it's done:
Look for a preset in particle_emitterpresets.c, for example ParticleEmitter_Default
These lines are called somewhere inside App_Start()
These lines are called somewhere inside App_PostUpdate()
For emitters that don't loop infinitely, add conditionals to activate the emitter
A struct that represents a particle.
Particles are created and managed by a ParticleEmitter.
| typedef struct ParticleEmitter ParticleEmitter |
A struct that represents the configurations of a particle emitter.
Emitter is responsible for creating and managing particles. Emitter presets (such as fire, smoke, gunshots, etc.) can be created and reused inside particle_emitterpresets.h and .c Emitters themselves can be created with ParticleEmitter_CreateDefault() and then modified as needed.
| void ParticleEmitter_ActivateOnce | ( | ParticleEmitter * | emitter | ) |
Activates the emitter once.
| emitter | The emitter to activate. |
Activates the emitter once.
Reactivates a particle emitter that was inactive, setting up its state for another emission cycle.
| emitter | A pointer to the particle emitter |
| void ParticleEmitter_Deactivate | ( | ParticleEmitter * | emitter | ) |
Deactivates the emitter.
| emitter | The emitter to deactivate. |
Deactivates the emitter.
Stops a particle emitter from emitting new particles, though existing particles will continue to update and render.
| emitter | A pointer to the particle emitter |
| void ParticleEmitter_DestroyEmitter | ( | ParticleEmitter * | emitter | ) |
Destroys the emitter and frees its memory.
| emitter | The emitter to destroy. |
Destroys the emitter and frees its memory.
Frees all resources associated with a particle emitter, including particle array and timer.
| emitter | A pointer to the particle emitter |
| void ParticleEmitter_Emit | ( | ParticleEmitter * | emitter | ) |
Emits particles from the emitter.
| emitter | The emitter to emit particles from. |
Emits particles from the emitter.
Creates a new particle with initial properties derived from the emitter settings plus appropriate randomization.
| emitter | A pointer to the particle emitter |
| int ParticleEmitter_GetNextReady | ( | ParticleEmitter * | emitter | ) |
Gets the next available particle index.
| emitter | The emitter to get the next available particle index from. |
Gets the next available particle index.
Particle is available of it's dead, basically. Searches through the particle array to find the first particle that is not alive.
| emitter | A pointer to the particle emitter |
| bool ParticleEmitter_ParticlesAlive | ( | ParticleEmitter * | emitter | ) |
Checks if the emitter has any particles alive.
| emitter | The emitter to check. |
Checks if the emitter has any particles alive.
Scans through all particles in the emitter to determine if any are still active.
| emitter | A pointer to the particle emitter |
| void ParticleEmitter_Render | ( | ParticleEmitter * | emitter | ) |
Renders the particles of an emitter.
| emitter | The emitter to render the particles of. |
Renders the particles of an emitter.
Draws all active particles with their current color, size, and position.
| emitter | A pointer to the particle emitter |
| void ParticleEmitter_SetMaxParticles | ( | ParticleEmitter * | emitter, |
| int | maxParticles | ||
| ) |
Sets the maximum number of particles for an emitter.
| emitter | The emitter to set the maximum particles for. |
| maxParticles | The maximum number of particles. |
Sets the maximum number of particles for an emitter.
This is probably never going to be used, since this is already set inside particle_emitterpreset. Only use this if (for some reason) you want to change a particle emitter's max particles in the middle of a game
| emitter | A pointer to the particle emitter |
| maxParticles | The target max particle number |
| void ParticleEmitter_Update | ( | ParticleEmitter * | emitter | ) |
Updates the emitter.
| emitter | The emitter to update. |
Updates the emitter.
Updates all aspects of a particle emitter including emission of new particles, updating existing particles, and handling emitter lifecycle events.
| emitter | A pointer to the particle emitter |
| void ParticleEmitter_UpdateParticles | ( | ParticleEmitter * | emitter | ) |
Updates the particles of an emitter.
| emitter | The emitter to update the particles of. |
Updates the particles of an emitter.
Processes all active particles, updating their position, color, size, and rotation based on their current state and lifecycle.
| emitter | A pointer to the particle emitter |