Last active
May 15, 2016 04:49
-
-
Save Beeblerox/b5a17d45077b4553cd919e10c4f88675 to your computer and use it in GitHub Desktop.
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
package; | |
import flash.geom.Rectangle; | |
import flixel.FlxSprite; | |
import flixel.text.FlxText; | |
import flixel.util.FlxColor; | |
import flixel.util.FlxDestroyUtil; | |
class CrookedText extends FlxSprite | |
{ | |
private var letter:FlxText; | |
public function new(?text:FlxText, angleRange:Int = 10, yRange:Int = 5, borderX:Int = 0, borderY:Int = 0, backGround:FlxColor = FlxColor.TRANSPARENT) | |
{ | |
super(); | |
letter = new FlxText(); | |
letter.antialiasing = true; | |
if (text != null) | |
generate(text, angleRange, yRange, borderX, borderY, backGround); | |
} | |
public function generate(text:FlxText, angleRange:Int = 10, yRange:Int = 5, borderX:Int = 0, borderY:Int = 0, backGround:FlxColor = FlxColor.TRANSPARENT) | |
{ | |
var tw:Float = text.width; // force text field graphic regeneration. | |
var w:Int = 2 * borderX + text.frameWidth; | |
var h:Int = 2 * borderY + text.frameHeight; | |
makeGraphic(w, h, backGround); | |
letter.setFormat(text.font, text.size, text.color); | |
for (i in 0...text.text.length) | |
{ | |
letter.text = text.text.charAt(i); | |
var letterBounds:Rectangle = text.textField.getCharBoundaries(i); | |
if (letterBounds == null) | |
continue; | |
letter.fieldWidth = letterBounds.width; | |
letter.height = letterBounds.height; | |
letter.updateFramePixels(); | |
var sign:Int = (Math.random() > 0.5) ? 1 : -1; | |
letter.angle = Math.random() * angleRange * sign; | |
var letterOffsetY:Float = Math.random() * yRange; | |
stamp(letter, Std.int(borderX + letterBounds.x), Std.int(borderY + letterBounds.y + yRange)); | |
} | |
} | |
override public function destroy():Void | |
{ | |
letter = FlxDestroyUtil.destroy(letter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment