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

Detailed Description

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.


Constructor & Destructor Documentation

thor::ParticleSystem::ParticleSystem ( ResourcePtr< const sf::Texture >  texture) [explicit]

Constructor: Create particle system from a whole sf::Texture.

Parameters:
textureShared 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.

Parameters:
textureShared resource pointer to the sf::Texture used as particle texture. May not be empty.
textureRectArea of the texture that is used to draw the particle.

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

Parameters:
affectorShared pointer to a derivate of Affector (non-empty).
timeUntilRemovalTime after which the affector is automatically removed from the system.
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.
void thor::ParticleSystem::AddEmitter ( Emitter::Ptr  emitter,
sf::Time  timeUntilRemoval 
)

Adds a particle emitter for a certain amount of time.

Parameters:
emitterShared pointer to a derivate of Emitter (non-empty).
timeUntilRemovalTime after which the emitter is automatically removed from the system.
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 ( 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.

Parameters:
dtFrame duration.

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