Class for simple particle systems. More...
Public Member Functions | |
ParticleSystem (ResourcePtr< const sf::Texture > texture) | |
Constructor: Create particle system from a whole sf::Texture. | |
ParticleSystem (ResourcePtr< const sf::Texture > texture, const sf::IntRect &textureRect) | |
Constructor: Create particle system using parts of a sf::Texture. | |
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 | AddAffector (Affector::Ptr affector, sf::Time timeUntilRemoval) |
Adds a particle affector for a certain amount of time. | |
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 | AddEmitter (Emitter::Ptr emitter, sf::Time timeUntilRemoval) |
Adds a particle emitter for a certain amount of time. | |
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 (sf::Time 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::Texture. During their lifetime, the particles can be affected in translation, rotation, scale and coloring.
This class is noncopyable.
thor::ParticleSystem::ParticleSystem | ( | ResourcePtr< const sf::Texture > | texture | ) | [explicit] |
Constructor: Create particle system from a whole sf::Texture.
texture | Shared resource pointer to the sf::Texture used as particle texture. May not be empty. |
thor::ParticleSystem::ParticleSystem | ( | ResourcePtr< const sf::Texture > | texture, |
const sf::IntRect & | textureRect | ||
) |
Constructor: Create particle system using parts of a sf::Texture.
texture | Shared resource pointer to the sf::Texture used as particle texture. May not be empty. |
textureRect | Area of the texture that is used to draw the particle. |
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::AddAffector | ( | Affector::Ptr | 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 | Shared pointer to a derivate of Affector (non-empty). |
timeUntilRemoval | Time after which the affector is automatically removed from the system. |
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::AddEmitter | ( | Emitter::Ptr | emitter, |
sf::Time | timeUntilRemoval | ||
) |
Adds a particle emitter for a certain amount of time.
emitter | Shared pointer to a derivate of Emitter (non-empty). |
timeUntilRemoval | Time after which the emitter is automatically removed from the system. |
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 | ( | 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. |