Skip to content

Instantly share code, notes, and snippets.

@azrafe7
Last active December 10, 2015 21:28
Show Gist options
  • Save azrafe7/4495125 to your computer and use it in GitHub Desktop.
Save azrafe7/4495125 to your computer and use it in GitHub Desktop.
TitleEntity using bloom and glitch effects from the punk.fx library.
package
{
import net.flashpunk.Entity;
import net.flashpunk.FP;
import punk.fx.effects.BloomFX;
import punk.fx.effects.GlitchFX;
import punk.fx.graphics.FXImage;
/**
* TitleEntity
* @author azrafe7
*/
public class TitleEntity extends Entity
{
[Embed(source="assets/Title.png")]
private const TITLE:Class;
private var titleImg:FXImage;
private var glitchFX:GlitchFX;
private var bloomFX:BloomFX;
public function TitleEntity()
{
// FXs
glitchFX = new GlitchFX(5, 10, 1);
bloomFX = new BloomFX(14, 190);
glitchFX.active = bloomFX.active = false;
// FXImage
titleImg = new FXImage(TITLE);
titleImg.effects.add([bloomFX, glitchFX]);
titleImg.centerOO();
super(400, 110, titleImg);
}
override public function update():void
{
// random alpha
if (Math.random() < .5) titleImg.alpha = 0.85 + Math.random() * .15;
// apply effects at random intervals
if (!glitchFX.active && Math.random() < .007) {
glitchFX.active = bloomFX.active = true; // activate effects
// disable effects after a short random period of time
FP.alarm(.1 + Math.random() * .4, function ():void
{
glitchFX.active = bloomFX.active = false;
});
}
super.update();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment