Created
October 20, 2013 07:28
-
-
Save FrancescoMaisto/7066021 to your computer and use it in GitHub Desktop.
Particle effects class
This file contains 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
package gameboard | |
{ | |
import starling.display.Sprite; | |
import starling.extensions.PDParticleSystem; | |
import starling.textures.Texture; | |
public class ParticleFXs extends Sprite | |
{ | |
// Embed configuration XML | |
[Embed(source="../../bin/particles/squares.pex", mimeType="application/octet-stream")] | |
private static const squares:Class; | |
[Embed(source="../../bin/particles/circles.pex", mimeType="application/octet-stream")] | |
private static const circles:Class; | |
[Embed(source="../../bin/particles/smoke.pex", mimeType="application/octet-stream")] | |
private static const smoke:Class; | |
[Embed(source="../../bin/particles/stars.pex", mimeType="application/octet-stream")] | |
private static const stars:Class; | |
[Embed(source="../../bin/particles/star.pex", mimeType="application/octet-stream")] | |
private static const star:Class; | |
public static const DURATION:Number = 8; // in seconds | |
private static const EMISSION_TIME:Object = {squares:0.3, circles:0.3, smoke:0.1, stars:1, star:60}; // in seconds | |
private var _particleEmissionTime:Number; | |
private var _particleSystem:PDParticleSystem; | |
private var _type:String; | |
// -------------------------------------------------------------------------------------------------- | |
public function ParticleFXs() | |
{ | |
super(); | |
} | |
// -------------------------------------------------------------------------------------------------- | |
public function create(type:String):void | |
{ | |
_type = type; | |
// instantiate embedded objects for Particle System | |
var psConfig:XML; | |
switch(type) | |
{ | |
case "squares": | |
psConfig = XML(new squares()); | |
break; | |
case "circles": | |
psConfig = XML(new circles()); | |
break; | |
case "smoke": | |
psConfig = XML(new smoke()); | |
break; | |
case "stars": | |
psConfig = XML(new stars()); | |
break; | |
case "star": | |
psConfig = XML(new star()); | |
break; | |
} | |
_particleEmissionTime = EMISSION_TIME[type]; | |
var psTexture:Texture = Game.assets.getTexture("particle_" + type); | |
// Create a new particle system | |
_particleSystem = new PDParticleSystem(psConfig, psTexture); | |
// Add it to the stage | |
this.addChild(_particleSystem); | |
// Performance improver | |
this.touchable = false; | |
} | |
// -------------------------------------------------------------------------------------------------- | |
public function start():void { | |
this.visible = true; | |
PlayScreen.gameOverJuggler.add(_particleSystem); | |
// start emitting particles and stop after the specified time (in seconds); | |
_particleSystem.start(_particleEmissionTime); | |
} | |
// -------------------------------------------------------------------------------------------------- | |
public function stop():void { | |
_particleSystem.stop(true); | |
} | |
// -------------------------------------------------------------------------------------------------- | |
public function removeFromJuggler():void | |
{ | |
PlayScreen.gameOverJuggler.remove(_particleSystem); | |
} | |
// -------------------------------------------------------------------------------------------------- | |
// SETTERS & GETTERS | |
public function get type():String { return _type; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment