Introduction to Particle Systems in Flash 9 and Actionscript 3

by Josh Tynjala

I’ve always been fascinated by the magical and organic effects that particle systems can help create. In video games, whenever you see smoke, flames, or steam, they’ve probably been made using particles. Systems can range anywhere from couple dozen to hundreds of particles, and span a wide range of effects. Simple changes to size, color, or transparency can cause surprisingly different results. Now, thanks to Flash 9′s performance increases, particle systems can provide a new level of realism within websites or Flash movies.

Screenshot of the flames particle system in Flash

Let me warn you that I am just starting to experiment with particle systems. The code for this project doesn’t necessarily reflect the most optimized way of handling them. I plan to come back to this subject again soon using bitmaps instead of vectors to demonstrate the differences. Both systems will have pros and cons, I’m sure. For today, the vector-based particles perform pretty well. Mainly it depends on your parameters. The more particles on the screen, the slower the swf will run. Likewise, blurring and transparency can slow things down too. It’s important to keep things simple. Many cool effects can be made without needing a lot complexity.

Let’s dive right in!

//Instantiate a SteamParticleSystem
//Note: There are constructor parameters, but the defaults are good for most situations
var steam:SteamParticleSystem = new SteamParticleSystem();

//Optional parameters
steam.lifetime = 500; //how long a particle will be visible
steam.size = 10; //the size of an individual particle
steam.color = 0xffffdd; //the color of a particle
steam.transparency = 0.5; //particle transparency
steam.baseBlur = 20; //the starting blur
steam.blurRange = 10; //additional blur added to the base over time
steam.jitter = 10; //horizontal velocity (randomly changes between 0 and jitter)
steam.baseVelocity = new Point(0, -2); //vertical velocity

//Standard Sprite stuff
steam.y = this.stage.stageHeight;
steam.x = this.stage.stageWidth / 2;
this.addChild(steam);

//Start up the system!
steam.start();

Several parameters allow you to tweak the system and give you different effects. Larger steam particles could mean that a valve on a steam pipe is open wider. Flames with a higher jitter might make them look like they’re burning wildly in the wind. These systems are flexible, and experimentation will help you achieve the look you want. All three of the effects I built actually run from very similar code. The particles are circles with low alpha that have been blurred. The smoke is the most basic effect that only features movement. Steam adds size changing to the mix, and the flames take it a step further to change the color too.

Working on this project was a lot of fun. I spent a good deal of time tweaking things here and there, so it takes some patience, but seeing so many different effects with such basic changes feels very rewarding. I encourage you to download the source code, and build your own cool effects based on my examples.

About the Author

Josh Tynjala is an indie game developer, entrepreneur, Flash and Flex mercenary, and bowler hat enthusiast.

Discussion
  1. [...] The particle system experiments haven’t changed too much. I made a few minor tweaks here and there to adjust for the changes between Beta 3 and RTM and I added more documentation. Hopefully I’ll find some time to do some more experiments with particles soon. [...]

    posted by Projects updated for Flex 2! » Zeus Labs » Flash and Actionscript Insights from a San Diego Developer and Designer on 07.06.2006
  2. Looks like you build a pretty cool thing, I do have some issues tho (hope you don’t mind):

    I’ve gone through your code, I noticed you never use removeChild or delete or anything to remove any particles, running your example I could see the memory usage slowly rising over time. So that’s a bit of a memory leak you might want to patch.

    Besides this I also wonder why you keep a particles array which holds all the particles, since Particle extends Sprite, so is allready managed and accesible through getChildAt and addChild etc. (but perhaps an array is faster access, that would be nice to know).

    posted by Meinte on 08.17.2006
  3. [...] Back in May, I spent some time experimenting with particle systems in Flash 9 and Actionscript 3. Thankfully, I found some time to come back to this project. I had one goal in mind: The concept of a particle system must be as flexible as possible. It could be anything from the flames and steam I created in my previous project to falling snow or even something more complex that involves artificial intelligence and flocking behaviors. [...]

    posted by More Fun with Flash 9 Particle Systems » Zeus Labs on 09.23.2006
  4. [...] System for Papervision3D A few weeks ago I made some modifications to the Zeus Lab particle system for Actionscript made by Josh Tynjala . The Josh’s particle system is neat, simple and if you [...]

    posted by Particle System for Papervision3D « Game Development Juice on 02.22.2008
Share Your Thoughts

To display code in comments: <pre>Code here. May be multiline. Format XML with &gt; and &lt; entities.</pre>

Some HTML allowed in comments: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>