me.BitmapText(scaleopt, settings)

new BitmapText(scaleopt, settings)

a bitmap font object

Parameters:
Name Type Attributes Default Description
scale Number <optional>
1.0
settings Object

the text configuration

Properties
Name Type Attributes Default Description
font String | Image

a font name to identify the corresponing source image

fontData String <optional>
settings.font

the bitmap font data corresponding name, or the bitmap font data itself

size Number <optional>

size a scaling ratio

lineWidth Number <optional>
1

line width, in pixels, when drawing stroke

textAlign String <optional>
"left"

horizontal text alignment

textBaseline String <optional>
"top"

the text baseline

lineHeight Number <optional>
1.0

line spacing height

anchorPoint me.Vector2d <optional>
{x:0.0, y:0.0}

anchor point to draw the text at

text String | Array.<String> <optional>

a string, or an array of strings

Example
// 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:
var 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);

Extends

Members

static lineHeight :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.

Default Value:
  • 1.0

static textAlign :String

Set the default text alignment (or justification),
possible values are "left", "right", and "center".

Default Value:
  • "left"

static textBaseline :String

Set the text baseline (e.g. the Y-coordinate for the draw operation),
possible values are "top", "hanging, "middle, "alphabetic, "ideographic, "bottom"

Default Value:
  • "top"

alpha :Number

Define the renderable opacity
Set to zero if you do not wish an object to be drawn

Inherited From:
Default Value:
  • 1.0
See:
  • me.Renderable#setOpacity
  • me.Renderable#getOpacity

ancestor :me.Container|me.Entity

a reference to the parent object that contains this renderable

Inherited From:
Default Value:
  • undefined

Methods

static draw(renderer, textopt, xopt, yopt)

draw the bitmap font

Parameters:
Name Type Attributes Description
renderer me.CanvasRenderer | me.WebGLRenderer

Reference to the destination renderer instance

text String <optional>
x Number <optional>
y Number <optional>

static measureText(textopt, retopt) → {TextMetrics}

measure the given text size in pixels

Parameters:
Name Type Attributes Description
text String <optional>
ret me.Rect <optional>

a object in which to store the text metrics

Returns:
TextMetrics -

a TextMetrics object with two properties: width and height, defining the output dimensions

static resize(scale)

change the font display size

Parameters:
Name Type Description
scale Number

ratio

Returns:
-

this object for chaining

static set(textAlign, scaleopt)

change the font settings

Parameters:
Name Type Attributes Description
textAlign String

("left", "center", "right")

scale Number <optional>
Returns:
-

this object for chaining

static setText(value)

change the text to be displayed

Parameters:
Name Type Description
value Number | String | Array.<String>

a string, or an array of strings

Returns:
-

this object for chaining