Classes
Interface Definitions
-
The raw data of a bitmap font.
Properties:
Name Type Description baseLineOffsetnumber The offset of the font face from the baseline.
charsRecord<string, RawCharData> The map of characters by character code.
distanceField{
type: "sdf" | "msdf" | "none",
range: number
}The range and type of the distance field for this font.
fontFamilystring The name of the font face.
fontSizenumber The size of the font face in pixels.
lineHeightnumber The line-height of the font face in pixels.
pages{ id : number, file : string }[] The map of base page textures (i.e., sheets of glyphs).
-
The options for installing a new BitmapFont. Once installed the font will be available for use in the BitmapText. It can be accessed by the
fontFamilyproperty of the TextStyle.Install a new BitmapFont will create the characters provided for the font and store them in the cache. But don't worry, if a character is requested that hasn't been generated yet, it will be created on the fly.
Properties:
Name Type Default Description charsstring | (string | string[])[] BitmapFont.ALPHANUMERICCharacters included in the font set. You can also use ranges. For example,
[['a', 'z'], ['A', 'Z'], "!@#$%^&*()~{}[] "]. Don't forget to include spaces ' ' in your character set!namestring the name of the font, this will be the name you use in the fontFamily of text style to access this font
paddingnumber 4Padding between glyphs on texture atlas. Lower values could mean more visual artifacts and bleeding from other glyphs, larger values increase the space required on the texture.
resolutionnumber 1Render resolution for glyphs.
skipKerningboolean falseSkip generation of kerning information for the BitmapFont. If true, this could potentially increase the performance, but may impact the rendered text appearance.
styleTextStyle | TextStyleOptions Style options to render with BitmapFont.
-
Options for creating a BitmapFont.
-
Properties:
Name Type Description idnumber Unique id of character
kerningRecord<string, number> The kerning values for this character.
textureTexture The texture of the character.
xAdvancenumber Advancement to apply to next character.
xOffsetnumber x-offset to apply when rendering character
yOffsetnumber y-offset to apply when rendering character.
-
Options for HTML text style, extends TextStyle.
Properties:
Name Type Attributes Description cssOverridesArray<string> <optional>
CSS style(s) to add.
tagStylesRecord<string, HTMLTextStyleOptions> <optional>
Tag styles.
-
The raw data of a character in a bitmap font.
Properties:
Name Type Description heightnumber The height of the character in the page.
letterstring The letter of the character.
pagenumber The page of the font texture that the character is on.
widthnumber The width of the character in the page.
xnumber The x position of the character in the page.
ynumber The y position of the character in the page.
-
Options for the Text class.
Properties:
Name Type Description anchorPointData | number The anchor point of the text.
resolutionnumber The resolution of the text.
roundPixelsboolean Whether or not to round the x/y position.
styleTextStyle | TextStyle<Partial> | TextStyleOptions | HTMLTextStyle | Partial<HTMLTextStyle> | HTMLTextStyleOptions The text style
textTextString The copy for the text object. To split a line you can use '\n'.
Example
const text = new Text({ text: 'Hello Pixi!', style: { fontFamily: 'Arial', fontSize: 24, fill: 0xff1010, align: 'center', } }); -
Constructor options used for
TextStyleinstances.const textStyle = new TextStyle({ fontSize: 12, fill: 'black', });- See:
Properties:
Name Type Description align'left' | 'center' | 'right' | 'justify' Alignment for multiline text, does not affect single line text
breakWordsboolean Indicates if lines can be wrapped within words, it needs
wordWrapto be set totruedropShadowboolean | Partial<TextDropShadow> Set a drop shadow for the text
fillstring | Array<string> | number | Array<number> | CanvasGradient | CanvasPattern A canvas fillstyle that will be used on the text e.g., 'red', '#00FF00'. Can be an array to create a gradient, e.g.,
['#000000','#FFFFFF']MDNfontFamilystring | string[] The font family, can be a single font name, or a list of names where the first is the preferred font.
fontSizenumber | string The font size (as a number it converts to px, but as a string, equivalents are '26px','20pt','160%' or '1.6em')
fontStyle'normal' | 'italic' | 'oblique' The font style.
fontVariant'normal' | 'small-caps' The font variant.
fontWeight'normal' | 'bold' | 'bolder' | 'lighter' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' The font weight.
leadingnumber The height of the line, a number that represents the vertical space that a letter uses.
letterSpacingnumber The amount of spacing between letters, default is 0
lineHeightnumber The line height, a number that represents the vertical space that a letter uses
paddingnumber Occasionally some fonts are cropped. Adding some padding will prevent this from happening by adding padding to all sides of the text.
strokeStrokeInput A canvas fillstyle that will be used on the text stroke, e.g., 'blue', '#FCFF00'
textBaseline'alphabetic' | 'top' | 'hanging' | 'middle' | 'ideographic' | 'bottom' The baseline of the text that is rendered.
whiteSpace'normal' | 'pre' | 'pre-line' Determines whether newlines & spaces are collapsed or preserved "normal" (collapse, collapse), "pre" (preserve, preserve) | "pre-line" (preserve, collapse). It needs wordWrap to be set to true.
wordWrapboolean Indicates if word wrap should be used
wordWrapWidthnumber The width at which text will wrap, it needs wordWrap to be set to true
Type Definitions
A union of all text styles, including HTML, Bitmap and Canvas text styles.
- See:
A union of all text style options, including HTML, Bitmap and Canvas text style options.
A number, or a string containing a number.
Properties:
| Name | Type | Description |
|---|---|---|
ascent |
number |
Font ascent |
descent |
number |
Font descent |
fontSize |
number |
Font size |
Constructor options used for HTMLText instances.
Properties:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
style |
HTMLTextStyle | HTMLTextStyleOptions |
<optional> |
The style of the text. |
|
text |
string |
<optional> |
''
|
The string that you would like the text to display. |
A drop shadow effect.
Properties:
| Name | Type | Description |
|---|---|---|
alpha |
number |
Set alpha for the drop shadow |
angle |
number |
Set a angle of the drop shadow |
blur |
number |
Set a shadow blur radius |
color |
ColorSource |
A fill style to be used on the e.g., 'red', '#00FF00' |
distance |
number |
Set a distance of the drop shadow |
A string or number that can be used as text.