Class for simple particle systems. More...
Public Member Functions | |
ParticleSystem (const sf::Image &particleImage, const sf::IntRect &particleRect) | |
Constructor: Takes a part of an image for a particle. | |
ParticleSystem (const sf::Image &particleImage) | |
Constructor: Takes a whole image for a particle. | |
void | Swap (ParticleSystem &other) |
Swaps the contents of two instances in constant time. | |
void | AddAffector (Affector::Ptr affector) |
Adds a particle affector to the system. | |
void | RemoveAffector (Affector::Ptr affector) |
Removes a particle affector from the system. | |
void | ClearAffectors () |
Removes all Affector instances from the system. | |
bool | ContainsAffector (Affector::Ptr affector) const |
Checks whether an affector is currently stored in the particle system. | |
void | AddEmitter (Emitter::Ptr emitter) |
Adds a particle emitter to the system. | |
void | RemoveEmitter (Emitter::Ptr emitter) |
Removes a particle emitter from the system. | |
void | ClearEmitters () |
Removes all Emitter instances from the system. | |
bool | ContainsEmitter (Emitter::Ptr emitter) const |
Checks whether an emitter is currently stored in the particle system. | |
void | Update (float dt) |
Updates all particles in the system. | |
void | Draw (sf::RenderWindow &target) const |
Draws all particles in the system. | |
void | ClearParticles () |
Removes all particles that are currently in the system. | |
void | SetGlowing (bool glow) |
Enables/disables glow effect. | |
bool | IsGlowing () const |
Returns whether particles are currently drawn with a glow effect. | |
Related Functions | |
void | thor::swap (ParticleSystem &lhs, ParticleSystem &rhs) |
Exchanges the contents of two ParticleSystem instances. |
Class for simple particle systems.
Like sprites, particles are represented as sub-rectangles of sf::Image. During their lifetime, the particles can be affected in translation, rotation, scale and coloring.
This class is noncopyable.
thor::ParticleSystem::ParticleSystem | ( | const sf::Image & | particleImage, |
const sf::IntRect & | particleRect | ||
) |
Constructor: Takes a part of an image for a particle.
particleImage | Source image used for the particle (the sf::Image is copied). |
particleRect | Source rectangle of particleImage that marks the texture bounds. |
thor::ParticleSystem::ParticleSystem | ( | const sf::Image & | particleImage | ) | [explicit] |
Constructor: Takes a whole image for a particle.
particleImage | Image used for the particle (the sf::Image is copied). |
void thor::ParticleSystem::AddAffector | ( | Affector::Ptr | 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 | Shared pointer to a derivate of Affector (non-empty). |
void thor::ParticleSystem::AddEmitter | ( | Emitter::Ptr | emitter | ) |
Adds a particle emitter to the system.
emitter | Shared pointer to a derivate of Emitter (non-empty). |
void thor::ParticleSystem::ClearAffectors | ( | ) |
Removes all Affector instances from the system.
All particles lose the influence of any extern 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.
bool thor::ParticleSystem::ContainsAffector | ( | Affector::Ptr | affector | ) | const |
Checks whether an affector is currently stored in the particle system.
bool thor::ParticleSystem::ContainsEmitter | ( | Emitter::Ptr | emitter | ) | const |
Checks whether an emitter is currently stored in the particle system.
void thor::ParticleSystem::Draw | ( | sf::RenderWindow & | target | ) | const |
Draws all particles in the system.
target | The render window on which the particles are drawn. |
void thor::ParticleSystem::RemoveAffector | ( | Affector::Ptr | affector | ) |
Removes a particle affector from the system.
affector | Shared pointer to a derivate of Affector (non-empty). |
void thor::ParticleSystem::RemoveEmitter | ( | Emitter::Ptr | emitter | ) |
Removes a particle emitter from the system.
emitter | Shared pointer to a derivate of Emitter (non-empty). |
void thor::ParticleSystem::SetGlowing | ( | bool | glow | ) |
Enables/disables glow effect.
Specifies whether particles should be drawn with a glow effect. Glowing particles are especially visible on dark backgrounds.
void thor::ParticleSystem::Update | ( | float | 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. |