flixel
flixel copied to clipboard
`FILL` Alignment Mode for FlxText
I think some kind of alignment mode that fills itself with the text using the FieldWidth as a basis would be neat to see
Something similar to this
(this is what it looks like when I space the zeroes)
- Misses:0 / Score:0 - is what the raw text looks like
turns out this exists: https://api.haxeflixel.com/flixel/text/FlxTextAlign.html#JUSTIFY
I attached the text to a fixed sprite at the center of the screen with this constructor
then used setFormat to set the colors and alignment
this should just work but apparently it does not
I'm assuming JUSTIFY isn't actually doing anything in code because this seems to be the same as LEFT
Please just paste code in code tags, rather than using screenshots
also FlxText is just a openfl TextField rendered to a bitmap and drawn as a FlxSprite, so in order to get this to work we need openfl to implement justify alignment in TextField
indeed it appears that the problem lies with openfl. JUSTIFY will always look the same as LEFT if wordwrap is not enabled or if the text does not fill up an entire line. This matches most word editors.
Take the following example:
final field = new openfl.text.TextField();
field.wordWrap = true;
final format = field.defaultTextFormat;
format.align = JUSTIFY;
format.color = 0xFFffffff;
format.font = "Arial";
field.defaultTextFormat = format;
field.text = "Just as you take my hand"
+ " Just as you write my number down"
+ " Just as the drinks arrive"
+ " Just as they play your favorite song"
+ " As your bad day disappears"
+ " No longer wound up like a spring"
+ " Before you had too much"
+ " Come back in focus again";
field.width = 200;
field.height = 200;
FlxG.game.parent.addChild(field);
Appears like so:
and adding hard new lines like this:
field.text = "Just as you take my hand"
+ "\nJust as you write my number down"
+ "\nJust as the drinks arrive"
+ "\nJust as they play your favorite song"
+ "\nAs your bad day disappears"
+ "\nNo longer wound up like a spring"
+ "\nBefore you had too much"
+ "\nCome back in focus again";
result in the following:
rather than the desired look: