Ive been making a particle system in XNA and i am trying to create two particle effects. a firework explosion and a fountain firework.
the problem i am having is that when i add new particles to the explosion (im doing this fast because i want them to all spawn at the same time) the frame rate drops greatly.
i was wondering if anyone a solution to make this better. i saw that the official example uses a queue method. would this help the problem i am facing? or would it make the program slower to load as it would have to load all these particles into the queue at the start?
add new particle :
if (isActive)
{
timeSinceLastEmission += gameTime.ElapsedGameTime.Milliseconds;
if (emitterFrequency == 0 || timeSinceLastEmission >= emitterFrequency)
{
emitterFrequency = emissionInterval;
for (int i = 0; i < Math.Round(timeSinceLastEmission / emitterFrequency); i++)
{
if (particleList.Count < MaxParticles)
addParticle();
}
timeSinceLastEmission = 0;
}
}
draw function :
public void draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
for (int i = 0; i < particleList.Count; i++)
{
spriteBatch.Draw(particleList[i].texture,
particleList[i].position,
null,
particleList[i].color,
particleList[i].rotation,
particleList[i].origin,
particleList[i].textureScale,
SpriteEffects.None,
0);
}
spriteBatch.End();
}
any help would be greatly appreciated.