PIXI.BitmapText
class BitmapText extends PIXI.Container
A BitmapText object will create a line or multiple lines of text using bitmap font.
The primary advantage of this class over Text is that all of your textures are pre-generated and loading, meaning that rendering is fast, and changing text has no performance implications.
Supporting character sets other than latin, such as CJK languages, may be impractical due to the number of characters.
To split a line you can use '\n', '\r' or '\r\n' in your string.
PixiJS can auto-generate fonts on-the-fly using BitmapFont or use fnt files provided by: http://www.angelcode.com/products/bmfont/ for Windows or http://www.bmglyph.com/ for Mac.
You can also use SDF, MSDF and MTSDF BitmapFonts for vector-like scaling appearance provided by: https://github.com/soimy/msdf-bmfont-xml for SDF and MSDF fnt files or https://github.com/Chlumsky/msdf-atlas-gen for SDF, MSDF and MTSDF json files
A BitmapText can only be created when the font is loaded.
// in this case the font is in a file called 'desyrel.fnt'
let bitmapText = new PIXI.BitmapText("text using a fancy font!", {
fontName: "Desyrel",
fontSize: 35,
align: "right"
});
Constructor
new PIXI.BitmapText(text: string, style: Partial<IBitmapTextStyle>) → {}
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
text | string |
A string that you would like the text to display. |
||
style | Partial<IBitmapTextStyle> |
The style parameters. |
||
style.fontName | string |
The installed BitmapFont name. |
||
style.fontSize | number |
<optional> |
The size of the font in pixels, e.g. 24. If undefined, . this will default to the BitmapFont size. |
|
style.align | string |
<optional> |
'left' |
Alignment for multiline text ('left', 'center', 'right' or 'justify'), does not affect single line text. |
style.tint | number |
<optional> |
0xFFFFFF |
The tint color. |
style.letterSpacing | number |
<optional> |
0 |
The amount of spacing between letters. |
style.maxWidth | number |
<optional> |
0 |
The max width of the text before line wrapping. |
Summary
Properties from BitmapText
number |
The resolution / device pixel ratio of the canvas. |
string |
|
PIXI.ObservablePoint |
The anchor sets the origin point of the text. |
boolean |
Set to |
string |
The name of the BitmapFont. |
number |
The size of the font to display. |
number |
Additional space between characters. |
number |
|
number |
|
number |
The resolution / device pixel ratio of the canvas. |
boolean |
|
string |
The text of the BitmapText object. |
number |
|
number |
|
number |
|
PageMeshData[] |
Collection of page mesh data. |
boolean |
|
Methods from BitmapText
PIXI.Rectangle |
|
void |
|
void |
Renders text and updates it when needed. This should only be called if the BitmapFont is regenerated. |
Properties inherited from Container
T[] |
|
number |
The height of the Container, setting this will actually modify the scale to achieve the value set. |
boolean |
|
boolean |
|
boolean |
Should children be sorted by zIndex at the next updateTransform call. |
number |
The width of the Container, setting this will actually modify the scale to achieve the value set. |
Properties inherited from DisplayObject
Methods inherited from Container
Methods inherited from DisplayObject
Inherited Events from Container
Inherited Events from DisplayObject
|
|
|
|
|
|
Capture phase equivalent of |
|
|
|
|
|
Capture phase equivalent of |
|
Fired when the mouse pointer is moved over a DisplayObject and its descendant's hit testing boundaries. |
|
Capture phase equivalent of |
|
Fired when the mouse pointer exits a DisplayObject and its descendants. |
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
Fired when the pointer is moved over a DisplayObject and its descendant's hit testing boundaries. |
|
Capture phase equivalent of |
|
Fired when the pointer leaves the hit testing boundaries of a DisplayObject and its descendants. |
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
PIXI.FederatedWheelEvent |
Fired when a the user scrolls with the mouse cursor over a DisplayObject. |
PIXI.FederatedWheelEvent |
Capture phase equivalent of |
Public Properties
_resolution: number = PIXI.settings.RESOLUTION
The resolution / device pixel ratio of the canvas.
This is set to automatically match the renderer resolution by default, but can be overridden by setting manually.
anchor: PIXI.ObservablePoint
The anchor sets the origin point of the text.
The default is (0,0)
, this means the text's origin is the top left.
Setting the anchor to (0.5,0.5)
means the text's origin is centered.
Setting the anchor to (1,1)
would mean the text's origin point will be the bottom right corner.
maxLineHeight: number
The max line height. This is useful when trying to use the total height of the Text, i.e. when trying to vertically align.
maxWidth: number
The max width of this bitmap text in pixels. If the text provided is longer than the value provided, line breaks will be automatically inserted in the last whitespace. Disable by setting the value to 0.
resolution: number = 1
The resolution / device pixel ratio of the canvas.
This is set to automatically match the renderer resolution by default, but can be overridden by setting manually.
roundPixels: boolean = PIXI.settings.ROUND_PIXELS
If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation. Advantages can include sharper image quality (like text) and faster rendering on canvas. The main disadvantage is movement of objects may appear less smooth. To set the global default, change PIXI.settings.ROUND_PIXELS
textHeight: number
The height of the overall text, different from fontSize, which is defined in the style object.
textWidth: number
The width of the overall text, different from fontSize, which is defined in the style object.
Protected Properties
protected _activePagesMeshData: PageMeshData[]
Collection of page mesh data.
protected _roundPixels: boolean = PIXI.settings.ROUND_PIXELS
If true PixiJS will Math.floor() x/y values when rendering.
Public Methods
getLocalBounds() → {PIXI.Rectangle}
Validates text before calling parent's getLocalBounds
Type | Description |
---|---|
PIXI.Rectangle |
|
renderCanvas(renderer: PIXI.CanvasRenderer) → {void}
Renders the object using the Canvas renderer
Name | Type | Description |
---|---|---|
renderer | PIXI.CanvasRenderer |
The renderer |
Type | Description |
---|---|
void |
updateText() → {void}
Renders text and updates it when needed. This should only be called if the BitmapFont is regenerated.
Type | Description |
---|---|
void |