Class for particle systems. More...
Public Member Functions | |
ParticleSystem () | |
Default constructor. More... | |
ParticleSystem (ParticleSystem &&source) | |
Move constructor. | |
ParticleSystem & | operator= (ParticleSystem &&source) |
Move assignment operator. | |
void | setTexture (const sf::Texture &texture) |
Sets the used texture. More... | |
unsigned int | addTextureRect (const sf::IntRect &textureRect) |
Defines a new texture rect to represent a particle. More... | |
Connection | addAffector (std::function< void(Particle &, sf::Time)> affector) |
Adds a particle affector to the system. More... | |
Connection | addAffector (std::function< void(Particle &, sf::Time)> affector, sf::Time timeUntilRemoval) |
Adds a particle affector for a certain amount of time. More... | |
void | clearAffectors () |
Removes all affector instances from the system. More... | |
Connection | addEmitter (std::function< void(EmissionInterface &, sf::Time)> emitter) |
Adds a particle emitter to the system. More... | |
Connection | addEmitter (std::function< void(EmissionInterface &, sf::Time)> emitter, sf::Time timeUntilRemoval) |
Adds a particle emitter for a certain amount of time. More... | |
void | clearEmitters () |
Removes all emitter instances from the system. More... | |
void | update (sf::Time dt) |
Updates all particles in the system. More... | |
void | clearParticles () |
Removes all particles that are currently in the system. | |
Class for particle systems.
A particle system stores, updates and draws particles. It also stores emitter and affector functions that control how particles are generated and modified over time. To represent particles graphically, a particle system requires a texture, and optionally one or multiple texture rectangles.
This class is noncopyable.
thor::ParticleSystem::ParticleSystem | ( | ) |
Default constructor.
Requires a call to setTexture() and possibly addTextureRect() before the particle system can be used.
Connection thor::ParticleSystem::addAffector | ( | std::function< void(Particle &, sf::Time)> | affector | ) |
Adds a particle affector to the system.
Be aware that multiple affectors can interfere with each other. The affectors are applied in the order they were added to the system, therefore affectors at the end may overwrite particle states set by earlier affectors. To completely avoid the issue, only add orthogonal affectors (e.g. one for color, one for acceleration...).
affector | Affector function object which is copied into the particle system. |
Connection thor::ParticleSystem::addAffector | ( | std::function< void(Particle &, sf::Time)> | affector, |
sf::Time | timeUntilRemoval | ||
) |
Adds a particle affector for a certain amount of time.
Be aware that multiple affectors can interfere with each other. The affectors are applied in the order they were added to the system, therefore affectors at the end may overwrite particle states set by earlier affectors. To completely avoid the issue, only add orthogonal affectors (e.g. one for color, one for acceleration...).
affector | Affector function object which is copied into the particle system. |
timeUntilRemoval | Time after which the affector is automatically removed from the system. |
Connection thor::ParticleSystem::addEmitter | ( | std::function< void(EmissionInterface &, sf::Time)> | emitter | ) |
Adds a particle emitter to the system.
emitter | Emitter function object which is copied into the particle system. |
Connection thor::ParticleSystem::addEmitter | ( | std::function< void(EmissionInterface &, sf::Time)> | emitter, |
sf::Time | timeUntilRemoval | ||
) |
Adds a particle emitter for a certain amount of time.
emitter | Emitter function object which is copied into the particle system. |
timeUntilRemoval | Time after which the emitter is automatically removed from the system. |
unsigned int thor::ParticleSystem::addTextureRect | ( | const sf::IntRect & | textureRect | ) |
Defines a new texture rect to represent a particle.
Can be used to create different visual representations of a particle, for example different shapes of debris.
textureRect | Area of the texture that is used to draw the particle. |
void thor::ParticleSystem::clearAffectors | ( | ) |
Removes all affector instances from the system.
All particles lose the influence of any external affectors. Movement and lifetime is still computed.
void thor::ParticleSystem::clearEmitters | ( | ) |
Removes all emitter instances from the system.
Particles that are currently in the system are still processed, but no new ones are emitted until you add another emitter.
void thor::ParticleSystem::setTexture | ( | const sf::Texture & | texture | ) |
Sets the used texture.
Only one texture can be used at a time. If you need multiple particle representations, specify different texture rectangles using the method addTextureRect(). If no texture rect is added, the whole texture will be used.
texture | Reference to the sf::Texture used as particle texture. The texture must remain valid as long as the particle system uses it. |
void thor::ParticleSystem::update | ( | sf::Time | dt | ) |
Updates all particles in the system.
Invokes all emitters and applies all affectors. The lifetime of every particle is decreased, dead particles are removed.
dt | Frame duration. |