BitmapText
class BitmapText extends Renderable
a bitmap font object
Constructor
new BitmapText(x: number, y: number, settings: object) → {}
// Use me.loader.preload or me.loader.load to load assets
me.loader.preload([
{ name: "arial", type: "binary" src: "data/font/arial.fnt" },
{ name: "arial", type: "image" src: "data/font/arial.png" },
])
// Then create an instance of your bitmap font:
let myFont = new me.BitmapText(x, y, {font:"arial", text:"Hello"});
// two possibilities for using "myFont"
// either call the draw function from your Renderable draw function
myFont.draw(renderer, "Hello!", 0, 0);
// or just add it to the word container
me.game.world.addChild(myFont);
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | number |
position of the text object |
||
y | number |
position of the text object |
||
settings | object |
the text configuration |
||
settings.font | string | Image |
a font name to identify the corresponing source image |
||
settings.fontData | string |
<optional> |
settings.font |
the bitmap font data corresponding name, or the bitmap font data itself |
settings.size | number |
<optional> |
size a scaling ratio |
|
settings.fillStyle | Color | string |
<optional> |
a CSS color value used to tint the bitmapText (@see BitmapText.tint) |
|
settings.lineWidth | number |
<optional> |
1 |
line width, in pixels, when drawing stroke |
settings.textAlign | string |
<optional> |
"left" |
horizontal text alignment |
settings.textBaseline | string |
<optional> |
"top" |
the text baseline |
settings.lineHeight | number |
<optional> |
1.0 |
line spacing height |
settings.anchorPoint | Vector2d |
<optional> |
{x:0.0, y:0.0} |
anchor point to draw the text at |
settings.wordWrapWidth | number |
<optional> |
the maximum length in CSS pixel for a single segment of text |
|
settings.text | string | Array<string> |
<optional> |
a string, or an array of strings |
Summary
Properties from BitmapText
Color |
|
number |
|
string |
|
string |
|
number |
|
Methods from BitmapText
Properties inherited from Renderable
number |
|
boolean |
|
Container | Entity |
|
ObservableVector2d |
|
boolean |
|
string |
|
Body |
|
Matrix2d |
|
number |
|
boolean |
|
string |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
Rect | RoundRect | Polygon | Line | Ellipse |
|
string |
|
Function |
|
Application |
|
ObservableVector3d |
|
GLShader |
|
Color |
|
boolean |
|
Properties inherited from Rect
Methods inherited from Renderable
Methods inherited from Rect
Rect |
|
Rect |
|
boolean |
|
Rect |
|
boolean |
|
boolean |
|
boolean |
|
Rect |
|
Polygon |
|
Rect |
|
Methods inherited from Polygon
Array<number> |
|
boolean |
|
Polygon |
|
Polygon |
|
|
|
Polygon |
|
Polygon |
|
Polygon |
|
Public Properties
fillStyle: Color
Color
defines the color used to tint the bitmap text
lineHeight: number = 1.0
number
Set the line spacing height (when displaying multi-line strings).
Current font height will be multiplied with this value to set the line height.
textAlign: string = "left"
string
Set the default text alignment (or justification),
possible values are "left", "right", and "center".
textBaseline: string = "top"
string
Set the text baseline (e.g. the Y-coordinate for the draw operation),
possible values are "top", "hanging, "middle, "alphabetic, "ideographic, "bottom"
wordWrapWidth: number = -1
number
the maximum length in CSS pixel for a single segment of text. (use -1 to disable word wrapping)
Public Methods
draw(renderer: CanvasRenderer | WebGLRenderer, text: string, x: number, y: number) → {}
draw the bitmap font
Name | Type | Attributes | Description |
---|---|---|---|
renderer | CanvasRenderer | WebGLRenderer |
Reference to the destination renderer instance |
|
text | string |
<optional> |
|
x | number |
<optional> |
|
y | number |
<optional> |
measureText(text: string) → {TextMetrics}
measure the given text size in pixels
Name | Type | Attributes | Description |
---|---|---|---|
text | string |
<optional> |
Type | Description |
---|---|
TextMetrics |
a TextMetrics object with two properties: |
resize(scale: number) → {BitmapText}
change the font display size
Name | Type | Description |
---|---|---|
scale | number |
ratio |
Type | Description |
---|---|
BitmapText |
this object for chaining |
set(textAlign: string, scale: number) → {BitmapText}
change the font settings
Name | Type | Attributes | Description |
---|---|---|---|
textAlign | string |
("left", "center", "right") |
|
scale | number |
<optional> |
Type | Description |
---|---|
BitmapText |
this object for chaining |
setText(value: number | string | Array<string>) → {BitmapText}
change the text to be displayed
Name | Type | Default | Description |
---|---|---|---|
value | number | string | Array<string> | "" |
a string, or an array of strings |
Type | Description |
---|---|
BitmapText |
this object for chaining |
updateBounds(absolute: boolean) → {Bounds}
update the bounding box for this Bitmap Text.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
absolute | boolean |
<optional> |
true |
update the bounds size and position in (world) absolute coordinates |
Type | Description |
---|---|
Bounds |
this Bitmap Text bounding box Rectangle object |