Game Development Reference
In-Depth Information
private var particleAnimationFrames:Array
: Holds the faded animation frames for the
particles
private var particles:Array
: The
active
particle array
private var particlePool:Array
: The
inactive
particle array
private var particleCount:int
: Used for loops the active arrays
private var particlePoolCount:int
: Used for loops through the inactive arrays
private var tempParticle:BasicBiltArrayParticle
: A temporary object used in loops
private var particlePoolMax:int = 500
: The total for the pool
private var particlesPerExplode:int = particlePoolMax / 20
: The number of
particles needed for an explosion
Instantiating a particle in the pool
The
createParticlePool
function is called at the start of each level to ensure that the particles
created match the color of the enemy for that level. This function will be in the
com.efg.games.blastermines.ParticleManager
class:
public function createParticlePool(maxParticles:int):void {
particlePool = [];
particles = [];
for (var particleCtr:int=0;particleCtr<maxParticles;particleCtr++) {
var tempParticle:BasicBiltArrayParticle = new BasicBiltArrayParticle(0,799,0,799);
particlePool.push(tempParticle);
}
}
The function loops through a count of the passed in (
maxParticles)
and pushes them into the
particlePool
array.
Making a particle active
When a
Mine
is destroyed in the game, an explosion is created. The
createExplode
function does
this job. This function will be part if the
com.efg.games.blastermines.BlasterMines
class:
private function createExplode(xval:Number,yval:Number,parts:int):void {
for (var explodeCtr:int=0;explodeCtr<parts;explodeCtr++) {
particleManager.particlePoolCount = particleManager.particlePool.length-1;
if (particleManager.particlePoolCount > 0) {
tempParticle=particleManager.particlePool.pop();
tempParticle.lifeDelayCount=0;
tempParticle.x=xval;
tempParticle.y = yval;
tempParticle.nextX=xval;
tempParticle.nextY=yval;
tempParticle.speed = (Math.random() * 3) + 1;
tempParticle.frame = 0;
tempParticle.animationList = particleManager.particleAnimationFrames;
tempParticle.bitmapData = tempParticle.animationList[tempParticle.frame];