Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Experimenting with font alignment.
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