Thursday, March 13, 2008

Particle Engine.. theory behind it..

A particle engine, as explained in a latter post, is basically just a class/engine that can managed a large number of sprites with different alpha values.

Imagine having to control 100-150 sprites fading from 1 to 0 in alpha while moving in different directions in a normal Actionscript function...

A way to solve this is to create a generic Particle class that manages the life (and death) of each particle and does so in a way that you only once call the "AddParticle" method and from there on doesn't worry about it anymore.

First issue that arose while developing the 0.1 version of the engine was ActionScript 3.0 lack of a fast Array class for storing the particles. After googling around a bit I stumble across this project evolving around generic Game development datastructures in ActionScript 3.0

http://lab.polygonal.de/ds/

The obvious candidate for our particle engine is the "Linked list" structure... the internal Update() method in our engine class will iterate through our particles 1 at a time, but it will also need to be able to remove a given particle in the middle of our list .. so using a normal Array class would create an enormous overhead when splitting and joining the Array's after deletion.

So tonight I'll be written my own implementation of the classic Linked list structure in ActionScript 3.0 and hopefully completing the first 0.1 release of the particle engine within this week.

No comments: