Firework
This example uses basic physics behaviour to create a firework. By listening for the empty event on the emitter we set off a new firework when the previous one has burnt out.
package { import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.renderers.BitmapRenderer; import flash.display.Sprite; import flash.filters.BlurFilter; import flash.filters.ColorMatrixFilter; import flash.geom.Rectangle; [SWF(width='500', height='400', frameRate='60', backgroundColor='#000000')] public class Main extends Sprite { private var emitter:Emitter2D; public function Main() { emitter = new Firework(); var renderer:BitmapRenderer = new BitmapRenderer( new Rectangle( 0, 0, 500, 400 ) ); renderer.addFilter( new BlurFilter( 2, 2, 1 ) ); renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0 ] ) ); renderer.addEmitter( emitter ); addChild( renderer ); emitter.x = 250; emitter.y = 150; emitter.start(); } } }
package { import org.flintparticles.common.actions.Age; import org.flintparticles.common.actions.Fade; import org.flintparticles.common.counters.Blast; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.easing.Quadratic; import org.flintparticles.common.events.EmitterEvent; import org.flintparticles.common.initializers.ColorInit; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.common.initializers.SharedImage; import org.flintparticles.twoD.actions.Accelerate; import org.flintparticles.twoD.actions.LinearDrag; import org.flintparticles.twoD.actions.Move; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.initializers.Velocity; import org.flintparticles.twoD.zones.DiscZone; import flash.geom.Point; public class Firework extends Emitter2D { public function Firework() { counter = new Blast( 700 ); addInitializer( new SharedImage( new Dot( 2 ) ) ); addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); addInitializer( new Velocity( new DiscZone( new Point( 0, 0 ), 200, 120 ) ) ); addInitializer( new Lifetime( 5 ) ); addAction( new Age( Quadratic.easeIn ) ); addAction( new Move() ); addAction( new Fade() ); addAction( new Accelerate( 0, 50 ) ); addAction( new LinearDrag( 0.5 ) ); addEventListener( EmitterEvent.EMITTER_EMPTY, restart, false, 0, true ); } public function restart( ev:EmitterEvent ):void { start(); } } }
import org.flintparticles.common.actions.*; import org.flintparticles.common.counters.*; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.easing.Quadratic; import org.flintparticles.common.events.EmitterEvent; import org.flintparticles.common.initializers.*; import org.flintparticles.twoD.actions.*; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.initializers.*; import org.flintparticles.twoD.renderers.*; import org.flintparticles.twoD.zones.*; var emitter:Emitter2D = new Emitter2D(); emitter.counter = new Blast( 700 ); emitter.addInitializer( new SharedImage( new Dot( 2 ) ) ); emitter.addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); emitter.addInitializer( new Velocity( new DiscZone( new Point( 0, 0 ), 200, 120 ) ) ); emitter.addInitializer( new Lifetime( 5 ) ); emitter.addAction( new Age( Quadratic.easeIn ) ); emitter.addAction( new Move() ); emitter.addAction( new Fade() ); emitter.addAction( new Accelerate( 0, 50 ) ); emitter.addAction( new LinearDrag( 0.5 ) ); emitter.addEventListener( EmitterEvent.EMITTER_EMPTY, restart, false, 0, true ); var renderer:BitmapRenderer = new BitmapRenderer( new Rectangle( 0, 0, 500, 400 ) ); renderer.addFilter( new BlurFilter( 2, 2, 1 ) ); renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0 ] ) ); renderer.addEmitter( emitter ); addChild( renderer ); emitter.x = 250; emitter.y = 150; emitter.start(); function restart( ev:EmitterEvent ):void { Emitter2D( ev.target ).start(); }
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:f="http://flintparticles.org/2009/flint2d" xmlns:filters="flash.filters.*" width="500" height="400" backgroundColor="#000000"> <fx:Script> <![CDATA[ import org.flintparticles.common.easing.Quadratic; ]]> </fx:Script> <f:BitmapRenderer id="renderer" width="500" height="400"> <f:preFilters> <filters:BlurFilter blurX="2" blurY="2" quality="1"/> <filters:ColorMatrixFilter matrix="{[ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0 ]}"/> </f:preFilters> <f:emitters> <f:Emitter id="emitter" autoStart="true" x="250" y="150" emitterEmpty="emitter.start()"> <f:counter> <f:Blast startCount="700"/> </f:counter> <f:initializers> <f:ColorInit minColor="0xFFFFFF00" maxColor="0xFFFF6600"/> <f:Velocity> <f:DiscZone centerX="0" centerY="0" innerRadius="120" outerRadius="200"/> </f:Velocity> <f:SharedImage> <f:Dot radius="2"/> </f:SharedImage> <f:Lifetime lifetime="5"/> </f:initializers> <f:actions> <f:Move/> <f:Age easing="{Quadratic.easeIn}"/> <f:Fade/> <f:Accelerate x="0" y="50"/> <f:LinearDrag drag="0.5"/> </f:actions> </f:Emitter> </f:emitters> </f:BitmapRenderer> </s:Application>