List of all members | Public Member Functions
thor::ParticleSystem Class Reference

Class for particle systems. More...

Inheritance diagram for thor::ParticleSystem:
Inheritance graph

Public Member Functions

 ParticleSystem ()
 Default constructor. More...
 
 ParticleSystem (ParticleSystem &&source)
 Move constructor.
 
ParticleSystemoperator= (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

thor::ParticleSystem::ParticleSystem ( )

Default constructor.

Requires a call to setTexture() and possibly addTextureRect() before the particle system can be used.

Member Function Documentation

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

Parameters
affectorAffector function object which is copied into the particle system.
Returns
Object that can be used to disconnect (remove) the affector from the 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...).

Parameters
affectorAffector function object which is copied into the particle system.
timeUntilRemovalTime after which the affector is automatically removed from the system.
Returns
Object that can be used to disconnect (remove) the affector from the system.
Connection thor::ParticleSystem::addEmitter ( std::function< void(EmissionInterface &, sf::Time)>  emitter)

Adds a particle emitter to the system.

Parameters
emitterEmitter function object which is copied into the particle system.
Returns
Object that can be used to disconnect (remove) the emitter from the 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.

Parameters
emitterEmitter function object which is copied into the particle system.
timeUntilRemovalTime after which the emitter is automatically removed from the system.
Returns
Object that can be used to disconnect (remove) the emitter 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.

Parameters
textureRectArea of the texture that is used to draw the particle.
Returns
Index of the texture rect just added. This number shall be assigned to the Particle::textureIndex variable, in order to render a particle using textureRect.
See also
setTexture()
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.

Parameters
textureReference 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.

Parameters
dtFrame duration.

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