19
Aug/08
0

Proof of concept: Flexible 2D Particle System

Something very powerfull for creating reallistic and flexible effects is a particle system. This is a flexible and basic particle system I created about 2 months ago. Again this is just a proof of concept, currently the max. number of particles is about 400-500. But this can be greatly increased by removing the blur and replacing it with an image, this would however make it lose some of it’s flexibility. Below is a smoke demo, but the posibilities are endless, steam, fire, explosions to name a few…

Usage is as follows:
[sourcecode language='actionscript']import com.particles.particleSystem;

var scene:particleSystem = new particleSystem();
this.addChild(scene);
scene.pX = 40; // The x-position of the particle’s source
scene.pY = 50; // The y-position of the particle’s source
scene.vY = 0; // The speed on the y axis (can also be negative)
scene.vX = 4; // The speed on the x axis (can also be negative)
scene.deviation = 2; // The possible deviation from the standard speed
scene.transparency = 1; // The transparency of the particles (levels lower than 1 greatly deteriorate the performance
scene.color = 0×000000; // Colour of the particles
scene.lifetime = 5000; // Lifetime of the particles in milliseconds
scene.size = 10; // Size of the particles
scene.maxParticles = 300; // Maximum number of particles
scene.startBlur = 10; // The amount of blur
scene.bExplode = false; // Set this to true if you want to let the particles all explode at once

scene.start();[/sourcecode]
There is still quite some room for improvement, especially getting to know when to stop the particle system is a bit tricky.

Download the Particle System class