/** * Latest information on this project can be found at http://www.rogue-development.com/pulseParticles.xml * * Copyright (c) 2008 Marc Hughes * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software * is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * ------------------------------------------------------------------------------------------- * * Description: * The Pulse Particle engine gives a simple way to create complex particle effects. * * * **/ /* This is an example application using the Pulse Particle Engine */ package { import com.roguedevelopment.pulse.PulseEngine; import com.roguedevelopment.pulse.emitter.IParticleEmitter; import com.roguedevelopment.pulse.simple.SimpleParticles; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.KeyboardEvent; import flash.events.MouseEvent; import flash.events.TimerEvent; import flash.geom.Point; import flash.text.TextField; import flash.text.TextFormat; import flash.utils.Timer; [SWF(backgroundColor="#000000", frameRate="60", width="500", height="350")] public class Flinger extends Sprite { [Embed(source="example_assets/snowflake.png")] protected var snowflake:Class; [Embed(source="example_assets/man.png")] protected var man:Class; [Embed(source="example_assets/smoke.png")] protected var smoke:Class; [Embed(source="example_assets/spark.png")] protected var spark:Class; protected var lastEmitter:IParticleEmitter = null; protected var text:TextField; protected var timer:Timer = new Timer(8000); protected var examples:Array = [ ["{pps:10,x:3, y:11, width:550, height:1,size:15, color:2588900, movement:true, minSpeed:150, maxSpeed:150, minAngle:0, maxAngle:180.7, minScale:1, maxScale:1, gravity:1, bound:[0,320,550,30], lifespan:7910}", {randomFrame:true, bme:true, pps:10,x:3, y:11, width:550, height:1,size:3, color:2588900, movement:true, minSpeed:150, maxSpeed:150, minAngle:76.8, maxAngle:107.85, minScale:1, maxScale:1, gravity:1, stop:[0,320,550,30], lifespan:7910}] , ["{dot:true, size:10 , fade:[1000], minAngle:0, maxAngle:360, pps:9, maxSpeed: 20, minSpeed:0, lifespan:1000, x:0, y:0, movement:true , width:500, height:350}", {colorTransform:[0,1000,0,0,0,0,250,0], minScale:0.01, maxScale:1, dot:true, size:10 , fade:[1000], minAngle:0, maxAngle:360, pps:9, maxSpeed: 40, minSpeed:0, lifespan:1000, x:0, y:0, movement:true , width:500, height:350}] , [ "{ bound:[0,0,490,340], line:true, size:20 , rotateToAngle:true, fade:[19000], minAngle:180, gravity:4, maxAngle:180, pps:3, maxSpeed: 340, minSpeed:340, lifespan:19000, x:250, y:240, movement:true }", { bme:true, bound:[0,0,490,340], line:true, size:20 , rotateToAngle:true, fade:[19000], minAngle:180, gravity:4, maxAngle:180, pps:3, maxSpeed: 340, minSpeed:340, lifespan:19000, x:250, y:240, movement:true } ], ["{ image:smoke , xOscillate:[1,900], rotate:[-2,2], fade:[6000],minScale:0.5, maxScale:1, minAngle:180, maxAngle:360, pps:35, gravity:-0.7, maxSpeed: 13, minSpeed:4, lifespan:6000, x:250, y:300, movement:true }", { bme:true, colorTransform:[0,3000,1,1,0,0,0,0], image:smoke , xOscillate:[1,900], rotate:[-2,2], fade:[6000],minScale:0.5, maxScale:1, minAngle:180, maxAngle:360, pps:35, gravity:-0.7, maxSpeed: 13, minSpeed:4, lifespan:6000, x:250, y:300, movement:true }] , ["{ image:snowflake , pps:10,x:-100, y:0, width:600, height:1, movement:true, minSpeed:66.25, maxSpeed:140.95, minAngle:67.6, maxAngle:83.4, minScale:0.1, maxScale:1, xOscillate:[1,500], lifespan:7840}", { image:snowflake , pps:10,x:-100, y:0, width:600, height:1, movement:true, minSpeed:66.25, maxSpeed:140.95, minAngle:67.6, maxAngle:83.4, minScale:0.1, maxScale:1, xOscillate:[1,500], lifespan:7840}], ["{ image:spark , fade:[6000], scale:[4000,0.01,1], minAngle:210, maxAngle:330, pps:55, gravity:2, maxSpeed: 140, minSpeed:80, lifespan:6000, x:250, y:240, movement:true }", { bme:true, image:spark , fade:[6000], scale:[4000,0.01,1], minAngle:210, maxAngle:330, pps:55, gravity:2, maxSpeed: 140, minSpeed:80, lifespan:6000, x:250, y:240, movement:true }] , ["{ image:smoke , xOscillate:[1,900], rotate:[-2,2], fade:[6000],minScale:0.5, maxScale:1, minAngle:180, maxAngle:360, pps:35, gravity:-0.7, maxSpeed: 13, minSpeed:4, lifespan:6000, x:250, y:300, movement:true }", { bme:true, image:smoke , xOscillate:[1,900], rotate:[-2,2], fade:[6000],minScale:0.5, maxScale:1, minAngle:180, maxAngle:360, pps:35, gravity:-0.7, maxSpeed: 13, minSpeed:4, lifespan:6000, x:250, y:300, movement:true }] , [ "{ minScale:0.01, maxScale:3, x:50, y:200, pps:80, lifespan:1000, movement:true, minAngle:0, maxAngle:360}" , { speed:[80,200], minScale:0.01, maxScale:3, x:250, y:200, pps:80, lifespan:1000, movement:true, minAngle:0, maxAngle:360} ], [ "{ speed:[20,40], x:250, y:200, rotateToAngle:true, line:true, size:4, lifespan:4000, movement:true, mouseSwarm:stage}", { speed:[40,140], angle:[0,0], x:250, y:200, rotateToAngle:true, line:true, size:4, lifespan:4000, movement:true, mouseSwarm:stage}], ["{ image:man , pps:10, pointSwarm:new Point(1000,700), rotateToAngle:true, maxSpeed: 110, minSpeed:100, scale:[5000, 0.05,1 ], lifespan:7000, x:20, y:20, movement:true }", { image:man , pps:10, angle:[0,360], pointSwarm:new Point(1000,700), rotateToAngle:true, maxSpeed: 110, minSpeed:100, scale:[5000, 0.05,1 ], lifespan:7000, x:20, y:20, movement:true }] ]; public function Flinger() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; var bmd:BitmapData = new BitmapData(500,500,true,0x000000); var bm:Bitmap = new Bitmap(bmd); addChild(bm); text = new TextField(); text.textColor = 0xffffff; text.multiline = true; text.wordWrap = true; text.width = 500; var format:TextFormat = text.getTextFormat(); format.font = "Arial"; text.setTextFormat(format ); text.height = 34; addChild(text); PulseEngine.instance.root = this; stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown ); nextExample(); timer.addEventListener(TimerEvent.TIMER, onTimer ); timer.start() stage.addEventListener(MouseEvent.CLICK, onClick ); } protected function onTimer(event:TimerEvent) : void { nextExample(); } protected function onClick(event:MouseEvent) : void { nextExample(); timer.stop(); } protected function onKeyDown( event:KeyboardEvent) : void { nextExample(); timer.stop(); } protected function nextExample() : void { trace("next"); // PulseEngine.instance.stopAndRemoveAllParticles(); var example:Array = examples.shift(); examples.push(example); if( lastEmitter != null ) {lastEmitter.stop(); } text.text = example[0] ; lastEmitter = SimpleParticles.createEmitter( example[1] ); } } }