PrimaryFeather/Starling-Extension-Particle-System — pull request #10 by kutu (2012-10-29 16:18:43+00:00)
Title: make particle system more extensible

this patch don't change any logic, just do particle system more extensibility

example of usage:

#### Stars:

1. developer want to create some background stars effect in his "space wars" game
2. each star flying from left to right on whole area
3. developer don't want to wait while current particle system fill all area with stars
4. developer want to produce some number of stars on initialization
5. after this initialization, particle system should work as usual

```as3
package game.effects {

import ...

public class Stars extends ParticleSystem {

public function Stars() {
const numParticles:int = 100;

super(texture, numParticles / lifeSpan, numParticles, numParticles,
Context3DBlendFactor.SOURCE_ALPHA, Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA);

// randomly place 100 stars on initialization

mNumParticles = numParticles;
const w:Number = 600; // area width
for (var i:int = 0; i < numParticles; ++i) {
var particle:StarParticle = mParticles[i] as StarParticle;
initParticle(particle);
var rand:Number = Math.random();
particle.x = w * rand;
particle.totalTime *= 1.0 - rand;
}
}

override protected function createParticle():Particle {
...
}
override protected function initParticle(particle:Particle):void {
...
}
override protected function advanceParticle(particle:Particle, passedTime:Number):void {
...
}

}

}
```

#### Batch particle effect:

1. developer have some number of targets (100 flying enemies)
2. on each of this enemy developer want to add a trail effect
3. developer don't want to create 100 particle systems, because it cost to much fps, and draw calls
4. developer want to create this effect in batch, and just add targets to the particle system, and remove targets from it on the fly

```as3
package game.effects {

import ...

public class BatchTrail extends ParticleSystem {

public function BatchTrail(texture:Texture, numParticlesPerTarget:uint, lifeSpan:Number) {
super(texture, numParticlesPerTarget / lifeSpan, 0, 0,
Context3DBlendFactor.SOURCE_ALPHA, Context3DBlendFactor.ONE);
}

public function addTarget(target:DisplayObject):void {
...
raiseCapacity(...);
...
}
public function removeTarget(target:DisplayObject):void {
...
}

override protected function createParticle():Particle {
...
}
override protected function initParticle(particle:Particle):void {
...
}
override protected function advanceParticle(particle:Particle, passedTime:Number):void {
...
}

override protected function createAndAdvanceNewParticles(passedTime:Number):void {
...
// custom logic on create and advance new particles
...
}

}

}
```