I freakin love Flint
I finally got a chance to work with Flint for a project I’m working on and its just amazing how well thought out of a particle system it is. With a little time you can take regular boring animations and really put them over the top. With just a few lines of code I was able to add particle trails to the missile and asteroid animations I’m working on:
[SWF]http://www.chrisrebstock.com/stuff/flintexample/FlintExample.swf, 400, 400[/SWF]
If you can’t see the swf above, click here.
The code is really straightforward too. Here is the code for the missile trail particle emitter:
var smoke : Emitter = new Emitter();
smoke.counter = new Steady( 25, 75 );
smoke.addInitializer( new Lifetime( 2, 3 ) );
smoke.addInitializer( new Velocity( new DiscSectorZone( new Point( 0, 0 ), 40, 30, Math.PI * .25, Math.PI * .85 ) ) );
smoke.addInitializer( new SharedImage( new RadialDot( 6 ) ) );
smoke.addAction( new Age( ) );
smoke.addAction( new Move( ) );
smoke.addAction( new LinearDrag( 0.01 ) );
smoke.addAction( new Scale( 1, 10 ) );
smoke.addAction( new Fade( 0.15, 0 ) );
smoke.addAction( new RandomDrift( 12, 12 ) );
smoke.renderer = smokeRenderer;
smoke.x = 75;
smoke.y = 500;
smoke.start( );
It basically boils down to a few simple steps:
– create an emitter
– create a counter for your emitter to determine how many particles are released per second
– create a velocity for particles released, which entails determining a zone for how they are released (check the zones package in the Flint source to see all different types of shapes for how you emit your particles)
– create an image for your individual particles
– add actions to your emitter, which is how you customize the movement, color, style and other aspects of the particles
– create a renderer sprite to hold the particles emitted, which you usually want to be a separate and stationary sprite
– call the start() method on the emitter and animate the emitter if you need to move it
The source code also mentions some key optimizations I plan to take advantage of once I get the time. One important one is limiting the size of your renderer Sprite. You can see in my code I made it the entire size of the screen, its better to only make it the size that you’ll need to show all the particles being emitted.
Recent Comments