Bromeon
Public Member Functions | Related Functions
thor::ParticleSystem Class Reference

Class for simple particle systems. More...

Inheritance diagram for thor::ParticleSystem:
Inheritance graph

List of all members.

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.

Detailed Description

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.


Constructor & Destructor Documentation

thor::ParticleSystem::ParticleSystem ( const sf::Image &  particleImage,
const sf::IntRect &  particleRect 
)

Constructor: Takes a part of an image for a particle.

Parameters:
particleImageSource image used for the particle (the sf::Image is copied).
particleRectSource rectangle of particleImage that marks the texture bounds.
thor::ParticleSystem::ParticleSystem ( const sf::Image &  particleImage) [explicit]

Constructor: Takes a whole image for a particle.

Parameters:
particleImageImage used for the particle (the sf::Image is copied).

Member Function Documentation

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...).

Parameters:
affectorShared pointer to a derivate of Affector (non-empty).
Precondition:
affector has not been added yet.

Adds a particle emitter to the system.

Parameters:
emitterShared pointer to a derivate of Emitter (non-empty).
Precondition:
emitter has not been added yet.

Removes all Affector instances from the system.

All particles lose the influence of any extern affectors. Movement and lifetime is still computed.

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.

Checks whether an affector is currently stored in the particle system.

Returns:
true if affector is used by this particle system, false otherwise.

Checks whether an emitter is currently stored in the particle system.

Returns:
true if emitter is used by this particle system, false otherwise.
void thor::ParticleSystem::Draw ( sf::RenderWindow &  target) const

Draws all particles in the system.

Parameters:
targetThe render window on which the particles are drawn.

Removes a particle affector from the system.

Parameters:
affectorShared pointer to a derivate of Affector (non-empty).
Precondition:
affector is currently stored in the particle system.

Removes a particle emitter from the system.

Parameters:
emitterShared pointer to a derivate of Emitter (non-empty).
Precondition:
emitter is currently stored in the particle system.
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.

Parameters:
dtFrame duration.

The documentation for this class was generated from the following file: