Logo Tween
This example uses the TweenToZone Action to move the particles from one shaped zone to the other and back again. It uses three emitters, one to create the particles, a second to move the particles from one zone to the other, and a third to move them back again. In the code we listen for the particle dead event on each emitter and revive the dying particle and add it to the next emitter.
package { import org.flintparticles.common.events.ParticleEvent; import org.flintparticles.common.particles.Particle; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.renderers.PixelRenderer; import flash.display.Sprite; import flash.filters.BlurFilter; import flash.filters.ColorMatrixFilter; import flash.geom.Rectangle; [SWF(width='400', height='200', frameRate='60', backgroundColor='#000000')] public class Main extends Sprite { private var startEmitter:Emitter2D; private var tween1Emitter:Emitter2D; private var tween2Emitter:Emitter2D; public function Main() { startEmitter = new FirstEmitter(); tween1Emitter = new TweenToFlint(); tween2Emitter = new TweenToParticles(); var renderer:PixelRenderer = new PixelRenderer( new Rectangle( 0, 0, 400, 200 ) ); 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.97,0 ] ) ); renderer.addEmitter( startEmitter ); renderer.addEmitter( tween1Emitter ); renderer.addEmitter( tween2Emitter ); addChild( renderer ); startEmitter.addEventListener( ParticleEvent.PARTICLE_DEAD, moveToTween1 ); tween1Emitter.addEventListener( ParticleEvent.PARTICLE_DEAD, moveToTween2 ); tween2Emitter.addEventListener( ParticleEvent.PARTICLE_DEAD, moveToTween1 ); startEmitter.start(); tween1Emitter.start(); tween2Emitter.start(); } private function moveToTween1( event:ParticleEvent ):void { event.particle.revive(); tween1Emitter.addParticles( Vector.<Particle>( [ event.particle ] ), true ); } private function moveToTween2( event:ParticleEvent ):void { event.particle.revive(); tween2Emitter.addParticles( Vector.<Particle>( [ event.particle ] ), true ); } } }
package { import org.flintparticles.common.actions.Age; import org.flintparticles.common.counters.Blast; import org.flintparticles.common.easing.Quadratic; import org.flintparticles.common.initializers.ColorInit; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.twoD.actions.TweenToZone; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.initializers.Position; import org.flintparticles.twoD.zones.BitmapDataZone; public class FirstEmitter extends Emitter2D { public function FirstEmitter() { counter = new Blast( 5000 ); addInitializer( new ColorInit( 0xFFFFFF00, 0xCC6600 ) ); addInitializer( new Lifetime( 6 ) ); addInitializer( new Position( new BitmapDataZone( new FlintImage( 320, 80 ), 40, 60 ) ) ); addAction( new Age( Quadratic.easeInOut ) ); addAction( new TweenToZone( new BitmapDataZone( new ParticlesImage( 320, 80 ), 40, 60 ) ) ); } } }
package { import org.flintparticles.common.actions.Age; import org.flintparticles.common.easing.Quadratic; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.twoD.actions.TweenToZone; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.zones.BitmapDataZone; public class TweenToFlint extends Emitter2D { public function TweenToFlint() { addInitializer( new Lifetime( 6 ) ); addAction( new Age( Quadratic.easeInOut ) ); addAction( new TweenToZone( new BitmapDataZone( new FlintImage( 320, 80 ), 40, 60 ) ) ); } } }
package { import org.flintparticles.common.actions.Age; import org.flintparticles.common.easing.Quadratic; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.twoD.actions.TweenToZone; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.zones.BitmapDataZone; public class TweenToParticles extends Emitter2D { public function TweenToParticles() { addInitializer( new Lifetime( 6 ) ); addAction( new Age( Quadratic.easeInOut ) ); addAction( new TweenToZone( new BitmapDataZone( new ParticlesImage( 320, 80 ), 40, 60 ) ) ); } } }
import org.flintparticles.common.actions.Age; import org.flintparticles.common.counters.Blast; import org.flintparticles.common.easing.Quadratic; import org.flintparticles.common.events.ParticleEvent; import org.flintparticles.common.initializers.ColorInit; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.common.particles.Particle; import org.flintparticles.twoD.actions.TweenToZone; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.initializers.Position; import org.flintparticles.twoD.particles.Particle2D; import org.flintparticles.twoD.renderers.PixelRenderer; import org.flintparticles.twoD.zones.BitmapDataZone; var flintImage:BitmapData = new FlintImage( 320, 80 ); var particlesImage:BitmapData = new ParticlesImage( 320, 80 ); var startEmitter:Emitter2D = new Emitter2D(); startEmitter.counter = new Blast( 5000 ); startEmitter.addInitializer( new ColorInit( 0xFFFFFF00, 0xCC6600 ) ); startEmitter.addInitializer( new Lifetime( 6 ) ); startEmitter.addInitializer( new Position( new BitmapDataZone( flintImage, 40, 60 ) ) ); startEmitter.addAction( new Age( Quadratic.easeInOut ) ); startEmitter.addAction( new TweenToZone( new BitmapDataZone( particlesImage, 40, 60 ) ) ); var tween1Emitter:Emitter2D = new Emitter2D(); tween1Emitter.addInitializer( new Lifetime( 6 ) ); tween1Emitter.addAction( new Age( Quadratic.easeInOut ) ); tween1Emitter.addAction( new TweenToZone( new BitmapDataZone( flintImage, 40, 60 ) ) ); var tween2Emitter:Emitter2D = new Emitter2D(); tween2Emitter.addInitializer( new Lifetime( 6 ) ); tween2Emitter.addAction( new Age( Quadratic.easeInOut ) ); tween2Emitter.addAction( new TweenToZone( new BitmapDataZone( particlesImage, 40, 60 ) ) ); var renderer:PixelRenderer = new PixelRenderer( new Rectangle( 0, 0, 400, 200 ) ); 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.97,0 ] ) ); renderer.addEmitter( startEmitter ); renderer.addEmitter( tween1Emitter ); renderer.addEmitter( tween2Emitter ); addChild( renderer ); startEmitter.addEventListener( ParticleEvent.PARTICLE_DEAD, moveToTween1 ); tween1Emitter.addEventListener( ParticleEvent.PARTICLE_DEAD, moveToTween2 ); tween2Emitter.addEventListener( ParticleEvent.PARTICLE_DEAD, moveToTween1 ); startEmitter.start(); tween1Emitter.start(); tween2Emitter.start(); function moveToTween1( event:ParticleEvent ):void { event.particle.revive(); tween1Emitter.addParticles( Vector.<Particle>( [ event.particle ] ), true ); } function moveToTween2( event:ParticleEvent ):void { event.particle.revive(); tween2Emitter.addParticles( Vector.<Particle>( [ event.particle ] ), true ); }