Last active
December 10, 2015 21:28
-
-
Save azrafe7/4495125 to your computer and use it in GitHub Desktop.
TitleEntity using bloom and glitch effects from the punk.fx library.
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 | |
{ | |
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