Search code examples
performancexnaframe-rateparticles

XNA Particle system performance


I have a particle system using basic spritebatch, where the particles are being created and destroyed based on decremental alpha value till 0.

The perfomance of the system is quite poor on pc, and very poor on xbox, with about a hundred particles on screen before significant fps slow down, I've read around regarding how to improve performance but does anyone have any tips on how to implment them, for exmaple what is the best way to - reuse particles rather than kill()? Does the image size of each particle make a difference? if I don't rotate each particle will this help?

I've played around with each of these suggestions but don't receive any significant improvement - does anyone have any advice - is it worth going gpu rather than cpu based?


Solution

  • From what I recall destroying and creating particles slows down the performance substantially. You might want to reuse particles.

    Not sure about image size or rotation drastically reducing performance as long as the image isn't substantially large.

    I would have an array with swapping dead particles to the end of the active particles therefore processing only active particles.

    For example:

    Make an array of MAX particles;
    When you need a particle grab particle_array[count]; 
    Increment count.
    When a particle dies, decrement count, swap the particle with particle_array[count];
    Update only count particles;
    

    Hope this helps.