Explode Image
Here we use one of Flint’s utility functions to create many small particles from a single image. Then, by applying the Explode activity at the location of the mouse click, we blow the image apart.
package { import org.flintparticles.common.events.EmitterEvent; import org.flintparticles.common.particles.Particle; import org.flintparticles.threeD.actions.DeathZone; import org.flintparticles.threeD.actions.Explosion; import org.flintparticles.threeD.actions.Move; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.particles.Particle3DUtils; import org.flintparticles.threeD.renderers.DisplayObjectRenderer; import org.flintparticles.threeD.zones.FrustrumZone; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Point; import flash.geom.Rectangle; import flash.geom.Vector3D; [SWF(width='500', height='350', frameRate='60', backgroundColor='#000000')] public class Main extends Sprite { private var emitter:Emitter3D; private var bitmap:BitmapData; private var renderer:DisplayObjectRenderer; private var explosion:Explosion; public function Main() { bitmap = new Image1( 384, 255 ); renderer = new DisplayObjectRenderer(); renderer.camera.dolly( -400 ); renderer.camera.projectionDistance = 400; renderer.y = 175; renderer.x = 250; addChild( renderer ); emitter = new Emitter3D(); emitter.addAction( new Move() ); emitter.addAction( new DeathZone( new FrustrumZone( renderer.camera, new Rectangle( -290, -215, 580, 430 ) ), true ) ); prepare(); renderer.addEmitter( emitter ); emitter.start(); stage.addEventListener( MouseEvent.CLICK, explode, false, 0, true ); emitter.addEventListener( EmitterEvent.EMITTER_EMPTY, prepare ); } private function prepare( event:EmitterEvent = null ):void { if( explosion ) { emitter.removeAction( explosion ); explosion = null; } var particles:Vector.<Particle> = Particle3DUtils.createRectangleParticlesFromBitmapData( bitmap, 12, emitter.particleFactory, new Vector3D( -192, -127, 0 ) ); emitter.addParticles( particles, false ); } private function explode( ev:MouseEvent ):void { if( !explosion ) { var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) ); explosion = new Explosion( 8, new Vector3D( p.x, p.y, 50 ), 500 ); emitter.addAction( explosion ); } } } }
import org.flintparticles.common.events.EmitterEvent; import org.flintparticles.common.particles.Particle; import org.flintparticles.threeD.actions.*; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.particles.Particle3DUtils; import org.flintparticles.threeD.renderers.DisplayObjectRenderer; import org.flintparticles.threeD.zones.FrustrumZone; var explosion:Explosion; var bitmap:BitmapData = new Image1( 384, 255 ); var renderer:DisplayObjectRenderer = new DisplayObjectRenderer(); renderer.camera.dolly( -400 ); renderer.camera.projectionDistance = 400; renderer.y = 175; renderer.x = 250; addChild( renderer ); var emitter:Emitter3D = new Emitter3D(); emitter.addAction( new Move() ); emitter.addAction( new DeathZone( new FrustrumZone( renderer.camera, new Rectangle( -290, -215, 580, 430 ) ), true ) ); emitter.position = new Vector3D( 0, 0, 0 ); prepare(); renderer.addEmitter( emitter ); emitter.start(); stage.addEventListener( MouseEvent.CLICK, explode, false, 0, true ); emitter.addEventListener( EmitterEvent.EMITTER_EMPTY, prepare ); function prepare( event:EmitterEvent = null ):void { if( explosion ) { emitter.removeAction( explosion ); explosion = null; } var particles:Vector.<Particle> = Particle3DUtils.createRectangleParticlesFromBitmapData( bitmap, 12, emitter.particleFactory, new Vector3D( -192, -127, 0 ) ); emitter.addParticles( particles, false ); } function explode( ev:MouseEvent ):void { if( !explosion ) { var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) ); explosion = new Explosion( 8, new Vector3D( p.x, p.y, 50 ), 500 ); emitter.addAction( explosion ); } }
<?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/flint3d" xmlns:geom="flash.geom.*" width="500" height="350" backgroundColor="#000000" creationComplete="complete()"> <fx:Script> <![CDATA[ import org.flintparticles.common.events.EmitterEvent; import org.flintparticles.common.particles.Particle; import org.flintparticles.threeD.actions.Explosion; import org.flintparticles.threeD.particles.Particle3DUtils; private var explosion:Explosion; private var bitmap:BitmapData; private function complete():void { bitmap = new Image1( 384, 255 ); prepare(); addEventListener( MouseEvent.CLICK, explode, false, 0, true ); emitter.addEventListener( EmitterEvent.EMITTER_EMPTY, prepare ); } private function prepare( event:EmitterEvent = null ):void { if( explosion ) { emitter.removeAction( explosion ); explosion = null; } var particles:Vector.<Particle> = Particle3DUtils.createRectangleParticlesFromBitmapData( bitmap, 12, emitter.particleFactory, new Vector3D( -192, -127, 0 ) ); emitter.addParticles( particles, false ); } private function explode( ev:MouseEvent ):void { if( !explosion ) { var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) ); explosion = new Explosion( 8, new Vector3D( p.x - renderer.width / 2, p.y - renderer.height / 2, 50 ), 500 ); emitter.addAction( explosion ); } } ]]> </fx:Script> <f:DisplayObjectRenderer x="0" y="0" id="renderer" width="500" height="350"> <f:camera> <f:Camera id="camera" projectionDistance="400"> <f:position> <geom:Vector3D x="0" y="0" z="-400"/> </f:position> </f:Camera> </f:camera> <f:emitters> <f:Emitter id="emitter" autoStart="true"> <f:actions> <f:Move/> <f:DeathZone zoneIsSafe="true"> <f:FrustrumZone camera="{camera}"> <f:viewRect> <geom:Rectangle left="-290" top="-215" width="580" height="430"/> </f:viewRect> </f:FrustrumZone> </f:DeathZone> </f:actions> </f:Emitter> </f:emitters> </f:DisplayObjectRenderer> </s:Application>