SHARE
TWEET

CrookedText

JuiceBoxx May 15th, 2016 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package rowboat.effects;
  2.  
  3. import flash.geom.Rectangle;
  4. import flixel.FlxSprite;
  5. import flixel.text.FlxText;
  6. import flixel.util.FlxColor;
  7. import flixel.util.FlxDestroyUtil;
  8.  
  9. class CrookedText extends FlxSprite
  10. {
  11.     private var letter:FlxText;
  12.    
  13.     public function new(?text:FlxText, angleRange:Int = 10, yRange:Int = 5, borderX:Int = 0, borderY:Int = 0, backGround:FlxColor = FlxColor.TRANSPARENT)
  14.     {
  15.         super(text.x, text.y);
  16.        
  17.         letter = new FlxText();
  18.         letter.antialiasing = text.antialiasing;
  19.        
  20.         if (text != null)
  21.             generate(text, angleRange, yRange, borderX, borderY, backGround);
  22.     }
  23.    
  24.     public function generate(text:FlxText, angleRange:Int = 10, yRange:Int = 5, borderX:Int = 0, borderY:Int = 0, backGround:FlxColor = FlxColor.TRANSPARENT)
  25.     {
  26.         var w:Int = 2 * borderX + Std.int(text.fieldWidth);
  27.         var h:Int = 2 * borderY + text.frameHeight + yRange * 2;
  28.        
  29.         makeGraphic(w, h, backGround);
  30.        
  31.         if (text.alignment == "center")
  32.             x -= width / 2;
  33.         if (text.alignment == "right")
  34.             x -= width;
  35.        
  36.         letter.setFormat(text.font, text.size, text.color);
  37.         if (text.borderStyle != NONE)
  38.             letter.setBorderStyle(text.borderStyle, text.borderColor, text.borderSize, text.borderQuality);
  39.        
  40.         for (i in 0 ... text.text.length)
  41.         {
  42.             letter.text = text.text.charAt(i);
  43.            
  44.             var t:FlxText = new FlxText(text.x, text.y, 0, text.text, text.size, true);
  45.             t.font = text.font;
  46.            
  47.             var letterBounds:Rectangle = new Rectangle(((t.fieldWidth / t.text.length) * i), yRange + borderY, t.fieldWidth / t.text.length, t.frameHeight);
  48.            
  49.             letter.fieldWidth = letterBounds.width;
  50.             letter.height = letterBounds.height;
  51.            
  52.             letter.updateFramePixels();
  53.            
  54.             var sign:Int = (Math.random() > 0.5) ? 1 : -1;
  55.             letter.angle = Math.random() * angleRange * sign;
  56.            
  57.             var letterOffsetY:Float = Math.random() * yRange;
  58.            
  59.             stamp(letter, Std.int(borderX + letterBounds.x), Std.int(borderY + letterBounds.y + yRange));
  60.         }
  61.     }
  62.    
  63.     override public function destroy():Void
  64.     {
  65.         letter = FlxDestroyUtil.destroy(letter);
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top