Initializing A Particle System

Top  Previous  Next

The Particle System should be initialized from within the overridden AutoInitialize() function.  The first thing that should be done is the InitializeXParticleSystem() function should be called, where X is the type of particle system you chose to create.  This should always be the first function called when initializing a particle system as it resets most of the particle system variables to their default values.

 

The particle system initialization function takes a number of arguments:

 

Graphics Device and Content Manager - The first two arguments are the Graphics Device that the particle system should draw to, and the Content Manager that the particle system should use to load resources, such as Textures or Effect (i.e. shader) files.  These should typically be set to the Graphics Device and Content Manager that were passed into the AutoInitialize() function.

 

Number Of Particles To Allocate Memory For and Max Number Of Particles To Allow - The Number Of Particles To Allocate Memory For determines how much memory should initially be allocated for the particle system.  This value may change changed at run-time, and likely will be changed if the Auto Memory Manager is enabled (which it is by default).  The particle system can never hold more particles than it has memory allocated for.  The Max Number Of Particles To Allow specifies the maximum number of particles that the particle system can contain at any given moment.  If this value is less than the Number Of Particles To Allocate Memory For only this many particles will be allowed in the particle system, even though there is memory to allow more.  If this value is greater than the Number Of Particles To Allocate Memory For and the Auto Memory Manager is enabled to increase memory, the Auto Memory Manger will increase the memory as needed up to, but not greater than, this value.

 

Vertex Update Function - The default particle systems provide this function for you, and it is called UpdateVertexProperties.  This function essentially copies a particle's drawable properties, such as position, color, size, etc, into the vertex buffer.  Because sprite particles are drawn using a SpriteBatch they do not require an explicit vertex buffer, and thus do not require this parameter.

 

Texture - The asset name of the texture to use for the particles.