Angel 3.2
A 2D Game Prototyping Engine
Classes | Public Member Functions | Protected Attributes | List of all members
ParticleActor Class Reference

An Actor that draws and keeps track of drawing a particle system on screen. More...

#include <ParticleActor.h>

+ Inheritance diagram for ParticleActor:

Classes

struct  Particle
 

Public Member Functions

 ParticleActor ()
 
 ~ParticleActor ()
 
virtual void Update (float dt)
 
virtual void Render ()
 
void SetParticlesPerSecond (float pps)
 
void SetSystemLifetime (float lifetime)
 
void SetParticleLifetime (float lifetime)
 
void SetSpread (float radians)
 
void SetEndScale (float scale)
 
void SetEndColor (const Color &color)
 
void SetSpeedRange (float minSpeed, float maxSpeed)
 
void SetMinSpeed (float minSpeed)
 
void SetMaxSpeed (float maxSpeed)
 
void SetGravity (const Vector2 &gravity)
 
void SetAttractor (const Vector2 &attractor)
 
void SetAttractorStrength (float strength)
 
void SetMaxParticles (int maxParticles)
 
virtual const String GetClassName () const
 
- Public Member Functions inherited from Actor
 Actor ()
 
virtual ~Actor ()
 
void SetSize (float x, float y=-1.f)
 
void SetSize (const Vector2 &newSize)
 
const Vector2GetSize () const
 
const BoundingBox GetBoundingBox () const
 
virtual void SetPosition (float x, float y)
 
virtual void SetPosition (const Vector2 &pos)
 
const Vector2GetPosition () const
 
virtual void SetRotation (float rotation)
 
const float GetRotation () const
 
void SetColor (float r, float g, float b, float a=1.0f)
 
void SetColor (const Color &color)
 
const ColorGetColor () const
 
void SetAlpha (float newAlpha)
 
const float GetAlpha () const
 
virtual void SetDrawShape (actorDrawShape drawShape)
 
const actorDrawShapeGetDrawShape () const
 
void UseDisplayList (int listIndex)
 
void MoveTo (const Vector2 &newPosition, float duration, bool smooth=false, String onCompletionMessage="")
 
void RotateTo (float newRotation, float duration, bool smooth=false, String onCompletionMessage="")
 
void ChangeColorTo (const Color &newColor, float duration, bool smooth=false, String onCompletionMessage="")
 
void ChangeSizeTo (const Vector2 &newSize, float duration, bool smooth=false, String onCompletionMessage="")
 
void ChangeSizeTo (float newSize, float duration, bool smooth=false, String onCompletionMessage="")
 
int GetSpriteTexture (int frame=0) const
 
bool SetSprite (const String &filename, int frame=0, GLint clampmode=GL_CLAMP, GLint filtermode=GL_LINEAR, bool optional=false)
 
void ClearSpriteInfo ()
 
void LoadSpriteFrames (const String &firstFilename, GLint clampmode=GL_CLAMP, GLint filtermode=GL_LINEAR)
 
void PlaySpriteAnimation (float delay, spriteAnimationType animType=SAT_Loop, int startFrame=-1, int endFrame=-1, const char *animName=NULL)
 
void SetSpriteFrame (int frame)
 
int GetSpriteFrame () const
 
const bool IsSpriteAnimPlaying () const
 
virtual void AnimCallback (String animName)
 
void SetUVs (const Vector2 &lowleft, const Vector2 &upright)
 
void GetUVs (Vector2 &lowleft, Vector2 &upright) const
 
const bool IsTagged (const String &tag)
 
void Tag (const String &newTag)
 
void Untag (const String &oldTag)
 
const StringSet & GetTags () const
 
const String & SetName (String newName)
 
const String & GetName () const
 
virtual void ReceiveMessage (Message *message)
 
void SetLayer (int layerIndex)
 
void SetLayer (const String &layerName)
 
virtual void LevelUnloaded ()
 
ActorGetSelf ()
 
- Public Member Functions inherited from Renderable
 Renderable ()
 
virtual ~Renderable ()
 
void Destroy ()
 
bool IsDestroyed ()
 
int GetLayer ()
 

Protected Attributes

Particle_particles
 
int _maxParticlesAlive
 
int _numParticlesAlive
 
float _particlesPerSecond
 
int _maxParticlesToGenerate
 
float _generationResidue
 
float _systemLifetime
 
float _particleLifetime
 
float _spreadRadians
 
Color _endColor
 
float _minSpeed
 
float _maxSpeed
 
float _endScale
 
Vector2 _gravity
 
Vector2 _attractor
 
float _attractorStrength
 
- Protected Attributes inherited from Actor
Vector2 _size
 
Vector2 _position
 
Color _color
 
float _rotation
 
float _UV [8]
 
actorDrawShape _drawShape
 
int _spriteCurrentFrame
 
int _spriteNumFrames
 
float _spriteFrameDelay
 
float _spriteCurrentFrameDelay
 
int _spriteTextureReferences [MAX_SPRITE_FRAMES]
 
spriteAnimationType _spriteAnimType
 
int _spriteAnimStartFrame
 
int _spriteAnimEndFrame
 
int _spriteAnimDirection
 
int _displayListIndex
 
StringSet _tags
 
String _name
 
String _currentAnimName
 
- Protected Attributes inherited from Renderable
bool _deleteMe
 
int _layer
 

Additional Inherited Members

- Static Public Member Functions inherited from Actor
static Actor *const GetNamed (const String &nameLookup)
 
static ActorCreate (const String &archetype)
 
static void SetScriptCreatedActor (Actor *a)
 
- Protected Member Functions inherited from Renderable
virtual void PreDestroy ()
 
- Static Protected Attributes inherited from Actor
static const float _squareVertices []
 
static float _circleVertices []
 
static float _circleTextureCoords []
 
static std::map< String, Actor * > _nameList
 
static Actor_scriptCreatedActor = NULL
 

Detailed Description

Particle systems are a very common feature of most games – they can be used for effects like fire, smoke, sparklies, etc. A discussion of the general use of particles is beyond the scope of this documentation, but if you're not familiar with the concept, this article by Jeff Lander is a good starting point.

http://www.double.co.nz/dust/col0798.pdf

Definition at line 46 of file ParticleActor.h.

Constructor & Destructor Documentation

ParticleActor::ParticleActor ( )

The default constructor creates a particle system that doesn't really do anything, since its maximum number of particles is 0. You'll need to call the "Set" functions below to make it look purty.

Definition at line 35 of file ParticleActor.cpp.

ParticleActor::~ParticleActor ( )

Deletes all the particles this Actor is keeping track of.

Definition at line 62 of file ParticleActor.cpp.

Member Function Documentation

void ParticleActor::Update ( float  dt)
virtual

Override of the normal Renderable::Update function. Changes the position and appearance of each individual particle appropriately.

Parameters
dtThe amount of time that's elapsed since the beginning of the last frame.

Reimplemented from Actor.

Definition at line 67 of file ParticleActor.cpp.

void ParticleActor::Render ( )
virtual

Override of the normal Renderable::Render function. Draws each particle.

Reimplemented from Actor.

Definition at line 182 of file ParticleActor.cpp.

void ParticleActor::SetParticlesPerSecond ( float  pps)

Change the rate at which this system releases particles. Default is 20 particles per second.

Parameters
ppsThe new release rate in particles per second.

Definition at line 240 of file ParticleActor.cpp.

void ParticleActor::SetSystemLifetime ( float  lifetime)

Change the system lifetime for this Actor. If the lifetime is set less than or equal to 0.0 (the default), the system will last until it's explicitly removed from the world. Otherwise the system will properly remove and deallocate itself when the elapsed time is up. (Useful for when you just want a burst of particles for a period of time and don't want to set up housekeeping timer.)

Parameters
lifetimeThe amount of time this system will persist, in seconds.

Definition at line 249 of file ParticleActor.cpp.

void ParticleActor::SetParticleLifetime ( float  lifetime)

Change the lifetime of each individual particle.

Parameters
lifetimeParticle lifetime in seconds

Definition at line 258 of file ParticleActor.cpp.

void ParticleActor::SetSpread ( float  radians)

Set the angle at which particles will disperse themselves. This affects their intial velocity only. Default is 0.0 (straight line to the right).

Parameters
radiansEmission angle in radians

Definition at line 267 of file ParticleActor.cpp.

void ParticleActor::SetEndScale ( float  scale)

Set the relative size each particle will grow (or shrink) to over its lifetime. The starting size is set with the normal Actor::SetSize function. The ending scale respects the starting aspect ratio.

Parameters
scaleThe multiplier gradually applied to each particle

Definition at line 272 of file ParticleActor.cpp.

void ParticleActor::SetEndColor ( const Color color)

Set the color each particle should be at the end of its life. Use an alpha of 0.0 to have the particles fade out over time. Starting color is set with the normal Actor::SetColor function.

Parameters
colorThe ending color for each particle in the system.

Definition at line 277 of file ParticleActor.cpp.

void ParticleActor::SetSpeedRange ( float  minSpeed,
float  maxSpeed 
)

Set the range of potential initial speeds for the particles. Each particle, at the start of its life, will randomly pick a speed in the given range.

Parameters
minSpeedThe speed (in GL units per second) of the slowest particle
maxSpeedThe speed (in GL units per second) of the fastest particle

Definition at line 282 of file ParticleActor.cpp.

void ParticleActor::SetMinSpeed ( float  minSpeed)

Set the lower range of potential initial speeds for the particles.

Parameters
minSpeedThe speed (in GL units per second) of the slowest particle

Definition at line 288 of file ParticleActor.cpp.

void ParticleActor::SetMaxSpeed ( float  maxSpeed)

Set the lower range of potential initial speeds for the particles.

Parameters
maxSpeedThe speed (in GL units per second) of the fastest particle

Definition at line 293 of file ParticleActor.cpp.

void ParticleActor::SetGravity ( const Vector2 gravity)

Set the vector which will pull the particles in a specific direction at a specified magnitude. The default is (0.0, -4.0).

Parameters
gravityThe vector in which the particles should be pulled (magnitude affecting the force of the pull).

Definition at line 298 of file ParticleActor.cpp.

void ParticleActor::SetAttractor ( const Vector2 attractor)

Set the attractor point for the particles – in addition to gravity, which gets applied as a vector, particles will be affected by their attraction to this point. Defaults to the origin (0, 0), but since the default attractor strength is zero, it will not actually affect any movement out of the box.

Parameters
attractorThe point to which all particles emitted by the system will be drawn. It is their destiny.

Definition at line 303 of file ParticleActor.cpp.

void ParticleActor::SetAttractorStrength ( float  strength)

Set the strength of the attractor, or how quickly particles will move to it. This does a very simple linear movement; it's not a force in the physics sense, so they won't accelerate towards it or anything like that.

Parameters
strengthThe magnitude of the vector between each particle and the attractor point.

Definition at line 308 of file ParticleActor.cpp.

void ParticleActor::SetMaxParticles ( int  maxParticles)

Set the maximum number of particles this system can keep track of at any one time. Decrease this number if you find you're having performance issues with your particles.

Parameters
maxParticlesThe maximum number of particles for this system.

Definition at line 313 of file ParticleActor.cpp.

virtual const String ParticleActor::GetClassName ( ) const
inlinevirtual

Used by the SetName function to create a basename for this class. Overridden from Actor::GetClassName.

Returns
The string "ParticleActor"

Reimplemented from Actor.

Definition at line 198 of file ParticleActor.h.


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