-
-
Save PrimaryFeather/6be832b36a6096d53786949796949706 to your computer and use it in GitHub Desktop.
Experimenting with font alignment.
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 starling | |
{ | |
import starling.display.DisplayObjectContainer; | |
import starling.text.BitmapFont; | |
import starling.text.TextField; | |
import starling.textures.Texture; | |
import starling.utils.Align; | |
public class BitmapFontAlignmentExperiment extends DisplayObjectContainer | |
{ | |
[Embed(source="../../assets/fonts/keep_calm_otl_numbers.fnt", mimeType="application/octet-stream")] | |
public static const keep_calm_fnt:Class; | |
[Embed(source="../../assets/fonts/keep_calm_otl_numbers.png")] | |
public static const keep_calm:Class; | |
public function BitmapFontAlignmentExperiment() | |
{ | |
var fontTexture:Texture = Texture.fromEmbeddedAsset(keep_calm); | |
var font:BitmapFont = new BitmapFont(fontTexture, XML(new keep_calm_fnt())); | |
TextField.registerCompositor(font, "KeepCalm"); | |
var alignments:Array = [Align.TOP, Align.CENTER, Align.BOTTOM]; | |
var currentX:Number = 50; | |
var currentY:Number = 50; | |
for each (var vAlign:String in alignments) | |
{ | |
var textField:TextField = new TextField(150, 120, "123"); | |
textField.format.setTo("KeepCalm", -1, 0xffffff, Align.CENTER, vAlign); | |
textField.x = currentX; | |
textField.y = currentY; | |
textField.border = true; | |
addChild(textField); | |
currentX += textField.width + 20; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment