class FlxText
package flixel.text
extends FlxSprite › FlxObject › FlxBasic
extended by FlxTextField, FlxTypeText, FlxInputText, FlxUIText
Extends FlxSprite to support rendering text. Can tint, fade, rotate and scale just like a sprite. Doesn't really animate though. Also does nice pixel-perfect centering on pixel fonts as long as they are only one-liners.
Autosizing
By default FlxText
is autosized to fit it's text.
To set a fixed size, use the fieldWidth
, fieldHeight
and autoSize
fields.
Constructor
new(X:Float = 0, Y:Float = 0, FieldWidth:Float = 0, ?Text:String, Size:Int = 8, EmbeddedFont:Bool = true)
Creates a new FlxText
object at the specified position.
Parameters:
X | The x position of the text. |
---|---|
Y | The y position of the text. |
FieldWidth | The |
Text | The actual text you would like to display initially. |
Size | The font size for this text object. |
EmbeddedFont | Whether this text field uses embedded fonts or not. |
Variables
alignment:FlxTextAlign
The alignment of the font. Note: autoSize
must be set to
false
or alignment
won't show any visual differences.
autoSize:Bool
Whether the fieldWidth
and fieldHeight
should be determined automatically.
Requires wordWrap
to be false
.
borderQuality:Float = 1
How many iterations do use when drawing the border. 0
: only 1 iteration, 1
: one iteration for every pixel in borderSize
A value of 1
will have the best quality for large border sizes, but might reduce performance when changing text.
NOTE: If the borderSize
is 1
, borderQuality
of 0
or 1
will have the exact same effect (and performance).
read onlyembedded:Bool
Whether this text field uses an embedded font (by default) or not.
Read-only - use systemFont
to specify a system font to use, which then automatically sets this to false
.
letterSpacing:Float
A number representing the amount of space that is uniformly distributed between all characters. The value specifies the number of pixels that are added to the advance after each character.
read onlyshadowOffset:FlxPoint
Offset that is applied to the shadow border style, if active.
x
and y
are multiplied by borderSize
. Default is (1, 1)
, or lower-right corner.
systemFont:String
The system font for this text (not embedded). Setting this sets embedded
to false
.
Passing an invalid font name (like ""
or null
) causes a default font to be used.
Methods
addFormat(Format:FlxTextFormat, Start:Int = -1, End:Int = -1):FlxText
Adds another format to this FlxText
Parameters:
Format | The format to be added. |
---|---|
Start | The start index of the string where the format will be applied. |
End | The end index of the string where the format will be applied. |
applyMarkup(input:UnicodeString, rules:Array<FlxTextFormatMarkerPair>):FlxText
Applies formats to text between marker characters, then removes those markers.
NOTE: this will clear all FlxTextFormat
s and return to the default format.
Usage:
text.applyMarkup(
"show $green text$ between dollar-signs",
[new FlxTextFormatMarkerPair(greenFormat, "$")]
);
Even works for complex nested formats like this:
var yellow = new FlxTextFormatMarkerPair(yellowFormat, "@");
var green = new FlxTextFormatMarkerPair(greenFormat, "<g>");
text.applyMarkup("Hey @Buddy@, what <g>is<g> going @on<g>?<g>@", [yellow, green]);
Parameters:
input | The text you want to format |
---|---|
rules |
|
removeFormat(Format:FlxTextFormat, ?Start:Int, ?End:Int):FlxText
Removes a specific FlxTextFormat
from this text.
If a range is specified, this only removes the format when it touches that range.
inlinesetBorderStyle(Style:FlxTextBorderStyle, Color:FlxColor = 0, Size:Float = 1, Quality:Float = 1):FlxText
Set border's style (shadow, outline, etc), color, and size all in one go!
Parameters:
Style | outline style |
---|---|
Color | outline color in |
Size | outline size in pixels |
Quality | outline quality - # of iterations to use when drawing. |
setFormat(?Font:String, Size:Int = 8, Color:FlxColor = FlxColor.WHITE, ?Alignment:FlxTextAlign, ?BorderStyle:FlxTextBorderStyle, BorderColor:FlxColor = FlxColor.TRANSPARENT, EmbeddedFont:Bool = true):FlxText
You can use this if you have a lot of text parameters to set instead of the individual properties.
Parameters:
Font | The name of the font face for the text display. |
---|---|
Size | The size of the font (in pixels essentially). |
Color | The color of the text in |
Alignment | The desired alignment |
BorderStyle | Which border style to use |
BorderColor | Color for the border, |
EmbeddedFont | Whether this text field uses embedded fonts or not |
Returns:
This FlxText
instance (nice for chaining stuff together, if you're into that).
stampOnAtlas(atlas:FlxAtlas):Bool
Stamps text onto specified atlas object and loads graphic from this atlas.
WARNING: Changing text after stamping it on the atlas will break the atlas, so do it only for
static texts and only after making all the text customizing (like size
, alignment
, color
, etc.)
Parameters:
atlas | atlas to stamp graphic to. |
---|
Returns:
whether the graphic was stamped on the atlas successfully