Created
February 20, 2011 02:24
-
-
Save daveWid/835618 to your computer and use it in GitHub Desktop.
Snow Class for the Flint Particle system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Snowfall using the Flint particle generator. | |
* | |
* @author Dave Widmer | |
*/ | |
package net.davewidmer.flint | |
{ | |
import flash.geom.Point; | |
import net.davewidmer.display.BaseSprite; | |
import org.flintparticles.common.counters.Steady; | |
import org.flintparticles.common.displayObjects.RadialDot; | |
import org.flintparticles.common.initializers.AlphaInit; | |
import org.flintparticles.common.initializers.ImageClass; | |
import org.flintparticles.common.initializers.ScaleImageInit; | |
import org.flintparticles.twoD.actions.DeathZone; | |
import org.flintparticles.twoD.actions.Move; | |
import org.flintparticles.twoD.actions.RandomDrift; | |
import org.flintparticles.twoD.emitters.Emitter2D; | |
import org.flintparticles.twoD.initializers.Position; | |
import org.flintparticles.twoD.initializers.Velocity; | |
import org.flintparticles.twoD.renderers.DisplayObjectRenderer; | |
import org.flintparticles.twoD.zones.LineZone; | |
import org.flintparticles.twoD.zones.PointZone; | |
import org.flintparticles.twoD.zones.RectangleZone; | |
public class Snow extends BaseSprite | |
{ | |
/** | |
* The particle emitter. | |
*/ | |
public var emitter:Emitter2D; | |
/** | |
* The particle renderer. | |
*/ | |
public var renderer:DisplayObjectRenderer; | |
/** | |
* Creates a new Snow instance. | |
*/ | |
public function Snow() | |
{ | |
super(); | |
} | |
/** | |
* Starts the snowfall. | |
*/ | |
public function start():void | |
{ | |
if(emitter == null) | |
{ | |
init(); | |
} | |
emitter.start(); | |
emitter.runAhead(15); | |
} | |
/** | |
* Stops the snowfall. | |
*/ | |
public function stop():void | |
{ | |
emitter.stop(); | |
} | |
/** @inheritDoc */ | |
protected override function init():void | |
{ | |
// Create the emitter. | |
emitter = new Emitter2D(); | |
emitter.counter = new Steady(50); | |
// Initialize the emitter. | |
emitter.addInitializer(new ImageClass(RadialDot, 2)); | |
emitter.addInitializer(new Position(new LineZone(new Point(-5, -5), new Point(945, -5)))); | |
emitter.addInitializer(new Velocity(new PointZone(new Point(0, 40)))); | |
emitter.addInitializer(new ScaleImageInit(0.75, 2)); | |
emitter.addInitializer(new AlphaInit(.25, 1)); | |
// Add actions to the emitter. | |
emitter.addAction(new Move()); | |
emitter.addAction(new DeathZone(new RectangleZone(-10, -10, 960, 320), true)); | |
emitter.addAction(new RandomDrift(15, 15)); | |
// Create the renderer. | |
renderer = new DisplayObjectRenderer(); | |
renderer.addEmitter(emitter); | |
addChild(renderer); | |
} | |
/** @inheritDoc */ | |
protected override function dispose():void | |
{ | |
// Nothing yet. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment