Vigilante Game Framework  1.0.0.8
A 2D/3D C++ Game Framework using SFML.
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
VEmitter Class Reference

A particle effects system that overrides VGroup. More...

#include <VEmitter.h>

Inheritance diagram for VEmitter:
VGroup VBase

Public Types

typedef VGroup VSUPERCLASS
 Used to call parent class functions when they are overrided in class.
 
- Public Types inherited from VGroup
typedef VBase VSUPERCLASS
 Used to call parent class functions when they are overrided in class.
 

Public Member Functions

 VEmitter (float x, float y, unsigned int MaxSize=0)
 
 VEmitter (sf::Vector2f position, unsigned int MaxSize=0)
 
VEmitterLoadParticlesFromFile (int Amount, const sf::String &Filename, bool Animated=false, int Width=1, int Height=1, const sf::IntRect &Rect=sf::IntRect(), bool RandomFrames=true)
 
VEmitterLoadParticles (int Amount, sf::Texture &Texture, bool Animated=false, int Width=1, int Height=1, const sf::IntRect &Rect=sf::IntRect(), bool RandomFrames=true)
 
VEmitterMakeParticles (int Amount, int Width, int Height, sf::Color Color=sf::Color::White)
 
virtual void Kill () override
 Kills the emitter and all of its particles.
 
virtual void Revive () override
 Revives the emitter.
 
virtual void Destroy () override
 Deletes and removes all particles before destroying any data stored in the emitter.
 
virtual void Update (float dt) override
 
virtual void Draw (sf::RenderTarget &RenderTarget) override
 
VEmitterStart (int Amount=0)
 
void Stop ()
 Stops emitter from emitting without the need to kill it.
 
bool IsRunning ()
 Check if the emitter is currently active.
 
virtual void EmitParticle ()
 Emits a single particle. This can be called directly if you don't want to emit a bunch of particles in sequence or as a special pattern.
 
- Public Member Functions inherited from VGroup
 VGroup (unsigned int maxSize=0)
 
int Length ()
 
VBaseAdd (VBase *object)
 
VBaseRemove (VBase *object, bool splice=false)
 
VBaseFirstAvailable ()
 
int FirstNULL ()
 
VBaseFirstExisting ()
 
VBaseFirstAlive ()
 
VBaseFirstDead ()
 
int CountAlive (bool Recursive=false)
 
int CountDead (bool Recursive=false)
 
VBaseGetRandom (int min=0, int max=0)
 
void ForEach (std::function< void(VBase *)> function, bool recursive=false)
 
void ForEachAlive (std::function< void(VBase *)> function, bool recursive=false)
 
void ForEachDead (std::function< void(VBase *)> function, bool recursive=false)
 
void ForEachExists (std::function< void(VBase *)> function, bool recursive=false)
 
VBaseGetGroupItem (int index)
 
template<class T >
T * GetGroupItemAsType (int index)
 
int GetIndexOfItem (VBase *object)
 
void OrganiseNULLS ()
 Sort nullptr members to the bottom of the group.
 
void Swap (int a, int b)
 
void Sort (std::function< bool(VBase *, VBase *)> func)
 
void Reverse ()
 Reverse order of group.
 
void Clear ()
 Clears the whole group (does not destroy any of the members, that must be done using the Destroy method).
 

Public Attributes

float Frequency = 0.5f
 The delay between particles emitting.
 
unsigned int AmountPerEmit = 1
 The amount of particles to activate per emit, in case you want more than one particle to appear at once.
 
bool Explosion = false
 If true, the emitter will emit all the particles at once, instead of at the rate of Frequency.
 
bool Circular = false
 If true, particles will be emitted at a normalized velocity (set with SpeedRange) or a random angle. If false, particles will be emitted with a randomized velocity (set with VelocityRange).
 
bool Constant = false
 If true, the emitter will emit particles continuously. If false, particles will emit until the number of particles emitted is greater than or equal to the amount parameter passed in (or the max set of amount).
 
sf::Vector2f Position
 Position to emit particles from.
 
sf::Vector2f Size
 Range relative to the position which to emit particles from (-Size/2 to Size/2)/.
 
bool Moves = true
 If true, particles should move.
 
bool Immovable = false
 If true, when particles have collided, their velocity or position cannot be effected.
 
int AllowCollisions = VObject::TOUCHALL
 Which sides are allowed to be collided with.
 
sf::Vector2f ScrollFactor
 The amount the object will appear to move when the camera scrolls (1.0f = Scrolls as fast as the camera, 0.5f = Scrolls half as fast as the camera). Good for parallax scrolling.
 
float RotateFactor = 1
 The amount the object will appear to rotate when the camera rotates (1.0f = Rotates as fast as the camera, 0.5f = Rotates half as fast as the camera). Good for parallax scrolling.
 
float ZoomFactor = 1
 The amount the object will appear to scale when the camera zooms (1.0f = Scales as fast as the camera, 0.5f = Scales half as fast as the camera). Good for parallax scrolling.
 
VRange< float > Lifespan
 The amount of time a particle is active for.
 
VRange< sf::Vector2f > VelocityRange
 The range of velocity the particle will be when emitted (used when Circular == false).
 
VRange< float > EmittingAngle
 The direction the particle will move in when emitted (used when Circular == true).
 
VRange< float > SpeedRange
 The speed of the particle when emitted (used when Circular == true).
 
VRange< float > AngleVelocityRange
 The velocity of rotation of the particle.
 
VRange< float > AngleAccelerationRange
 The acceleration of rotation of the particle.
 
VRange< float > AngleDragRange
 The drag of rotation of the particle.
 
VRange< float > AngleRange
 The angle the particle will initially emit at.
 
VRange< sf::Vector2f > DragRange
 The amount of drag movement of the particle.
 
VRange< sf::Vector2f > AccelerationRange
 The amount of acceleration of the particle.
 
VRange< float > ElasticityRange
 The bounciness of a particle.
 
VRangeBounds< sf::Vector2f > ScaleRange
 The scale of the particle, interpolates using LifeSpan as the total length of time.
 
VRangeBounds< sf::Color > ColourRange
 The colour tint of the particle, interpolates using LifeSpan as the total length of time.
 
VRangeBounds< float > AlphaRange
 The alpha transparency of the particle, interpolates using LifeSpan as the total length of time.
 
VParticleParticleInstance = new VParticle()
 The main instance of all particles in the emitter, can be overwritten to a class that inherits from VParticle, but will only be used when particles are loaded or created.
 
sf::RenderStates RenderState = sf::RenderStates::Default
 The RenderState that applies to all particles in the emitter.
 
- Public Attributes inherited from VBase
bool active = true
 Base can be updated using Update if true.
 
bool visible = true
 Base can be rendered using Draw if true.
 
bool alive = true
 Helper member that is mainly used filter out behaviours to objects which aren't alive in the scene.
 
bool exists = true
 Base can be updated and rendered if true, else it would no longer be treated as being part of the scene.
 
VType type = NONE
 Base object type, typically set in the constructor of an inherited object to specify what type it is.
 
uint32_t RefCount = 0
 Counts the amount of times the object is referenced in groups, ensures an object is only destroyed when no longer part of a single group.
 

Protected Member Functions

void setSize (int Amount, bool Animated, int Width, int Height, const sf::IntRect &Rect=sf::IntRect(), bool RandomFrames=true)
 

Protected Attributes

sf::VertexArray vertices
 All particles are rendered from a single set of vertices rendering a Quad.
 
bool disposible = false
 If true, texture will be destroyed within VSprite. Important if texture isn't loaded from VContent.
 
sf::Color mainTint
 Tint for all particles, particularly used for creating particles with the MakeParticles function.
 
bool running = false
 Allows the particles processed while running if true.
 
bool willKill = false
 Particles will be killed when the timer exceeds the emitter's timespan.
 
float timer = 0
 Timer that increases from start.
 
int counter = 0
 Counts the amount of particles currently emitted before the emitter shall stop.
 
int amount = 0
 Amount of particles to emit from start.
 
- Protected Attributes inherited from VGroup
std::vector< VBase * > members
 VBase List.
 
int length = 0
 Current amount of members in the list.
 
unsigned int MaxSize = 0
 Maximum Size of the list, used if VGroup is set to have a fixed size.
 

Additional Inherited Members

- Static Public Member Functions inherited from VBase
static const wchar_t * VString (const char *fmt,...)
 
static void VLog (const char *fmt,...)
 
static void VLogError (const char *fmt,...)
 
static void VClearLog ()
 

Detailed Description

A particle effects system that overrides VGroup.

Constructor & Destructor Documentation

◆ VEmitter() [1/2]

VEmitter::VEmitter ( float  x,
float  y,
unsigned int  MaxSize = 0 
)
inline
Parameters
xThe X Position of the emitter.
yThe Y Position of the emitter.
MaxSizeThe total size of the group that holds the particle data.

◆ VEmitter() [2/2]

VEmitter::VEmitter ( sf::Vector2f  position,
unsigned int  MaxSize = 0 
)
inline
Parameters
positionThe Position of the emitter.
MaxSizeThe total size of the group that holds the particle data.

Member Function Documentation

◆ Draw()

virtual void VEmitter::Draw ( sf::RenderTarget &  RenderTarget)
overridevirtual

Draws all active particles in the scene.

Parameters
RenderTargetThe game's sf::RenderTarget object to render data onto.

Reimplemented from VGroup.

◆ LoadParticles()

VEmitter* VEmitter::LoadParticles ( int  Amount,
sf::Texture &  Texture,
bool  Animated = false,
int  Width = 1,
int  Height = 1,
const sf::IntRect &  Rect = sf::IntRect(),
bool  RandomFrames = true 
)

Load set amount of particles from an sf::Texture object.

Parameters
AmountThe amount of particles will be loaded using this function. This can be less than or equal to the MaxSize if specified in the constructor.
TextureThe sf::Texture object for the texture.
AnimatedWhether the emitter should use the entire texture as one particle, or each particle should be a frame (texel) of that texture.
WidthThe frame width and width of the particle.
HeightThe frame height and height of the particle.
RectThe rectangle area of the texture for the emitter to use. By default this is the entire texture.
RandomFramesWhether the emitter should set frames in order from first to last, or random frames.
Returns
The VEmitter that is being loaded, typically the one that the function is being called from.

◆ LoadParticlesFromFile()

VEmitter* VEmitter::LoadParticlesFromFile ( int  Amount,
const sf::String &  Filename,
bool  Animated = false,
int  Width = 1,
int  Height = 1,
const sf::IntRect &  Rect = sf::IntRect(),
bool  RandomFrames = true 
)

Load set amount of particles from a file.

Parameters
AmountThe amount of particles will be loaded using this function. This can be less than or equal to the MaxSize if specified in the constructor.
FilenameThe filename and path of the texture used to load the particle. It will be loaded from VContent in VGlobal so it will also store the texture in this content manager.
AnimatedWhether the emitter should use the entire texture as one particle, or each particle should be a frame (texel) of that texture.
WidthThe frame width and width of the particle.
HeightThe frame height and height of the particle.
RectThe rectangle area of the texture for the emitter to use. By default this is the entire texture.
RandomFramesWhether the emitter should set frames in order from first to last, or random frames.
Returns
The VEmitter that is being loaded, typically the one that the function is being called from.

◆ MakeParticles()

VEmitter* VEmitter::MakeParticles ( int  Amount,
int  Width,
int  Height,
sf::Color  Color = sf::Color::White 
)

Makes a set of particles as a series of solid rectangles.

Parameters
AmountThe amount of particles will be loaded using this function. This can be less than or equal to the MaxSize if specified in the constructor.
WidthThe width of the particle.
HeightThe height of the particle.
ColorThe colour of the rectangle of the particle. Note that this colour will be mutliplied with the tint set in ColourRange.
Returns
The VEmitter that is being loaded, typically the one that the function is being called from.

◆ setSize()

void VEmitter::setSize ( int  Amount,
bool  Animated,
int  Width,
int  Height,
const sf::IntRect &  Rect = sf::IntRect(),
bool  RandomFrames = true 
)
protected

Sets up the texture the emitter will use when displaying textures.

Parameters
AmountTotal amount of particles to set up.
AnimatedUse the texel animation system to determine which section of the frames to use, or use the whole texture.
WidthWidth of the texture area to use.
HeightHeight of the texture area to use.
RectArea of the texture to use (default is the full texture size).
RandomFramesShould the emitter use frames incrementally or random frames.

◆ Start()

VEmitter* VEmitter::Start ( int  Amount = 0)

Start emitting particles.

Parameters
AmountThe amount of particles to emit. Default is all particles available in the emitter.

◆ Update()

virtual void VEmitter::Update ( float  dt)
overridevirtual

Updates all the particles in the emitter.

Parameters
dtDelta Time between the current and previous frames of the game.

Reimplemented from VGroup.


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