Reputation: 535
I have a FlxText
object which has properties like:
var CharHP:FlxText = new FlxText(1000, 500);
CharHP.Text = "HP: " + "9999";
CharHP.width = 300; CharHP.height = 200;
CharHP.alignment = "center";
I'm trying to align CharHP
to center and I expect these coordinates:
1000+(300/2), 500+(200/2)
However, the text is at:
1000, 500
Upvotes: 2
Views: 1543
Reputation: 1123
This works for me. Not sure why I don't have to import FlxTextAlign to get this working but feel free to refer to the API docs for more info. https://api.haxeflixel.com/flixel/text/FlxTextAlign.html
import flixel.text.FlxText;
...
var text = new FlxText( 300, "Your text to center", 24); // the field width argument is important
text.alignment = FlxTextAlign.CENTER; // This can be LEFT, RIGHT, JUSTIFY
Upvotes: 0
Reputation: 935
Text alignment centers the visual display of the text itself rather than the text box itself. The text box itself will always be "at" the x/y you supply in the constructor or by setting x and y directly.
Example:
[Left aligned text ]
[ Right aligned text]
[ Center aligned text ]
In all three cases the coordinates and size of the text box itself are the same, but the visual position of the text itself is different.
Upvotes: 2