Class: BitmapText

me. BitmapText

new BitmapText(scale, settings)

a bitmap font object
Parameters:
Name Type Argument Default Description
scale Number <optional>
1.0
settings Object the text configuration
Properties
Name Type Argument 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
Source:
bitmaptext.js, line 70
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.
Type:
  • Number
Default Value:
  • 1.0
Source:
bitmaptext.js, line 99

<static> textAlign :String

Set the default text alignment (or justification),
possible values are "left", "right", and "center".
Type:
  • String
Default Value:
  • "left"
Source:
bitmaptext.js, line 77

<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"
Type:
  • String
Default Value:
  • "top"
Source:
bitmaptext.js, line 88

alpha :Number

Define the renderable opacity
Set to zero if you do not wish an object to be drawn
Type:
  • Number
Inherited From:
Default Value:
  • 1.0
Source:
renderable.js, line 213
See:
  • me.Renderable#setOpacity
  • me.Renderable#getOpacity

ancestor :me.Container|me.Entity

a reference to the parent object that contains this renderable
Type:
Inherited From:
Default Value:
  • undefined
Source:
renderable.js, line 225

Methods

<static> draw(renderer, text, x, y)

draw the bitmap font
Parameters:
Name Type Argument Description
renderer me.CanvasRenderer | me.WebGLRenderer Reference to the destination renderer instance
text String <optional>
x Number <optional>
y Number <optional>
Source:
bitmaptext.js, line 241

<static> measureText(text, ret) → {TextMetrics}

measure the given text size in pixels
Parameters:
Name Type Argument Description
text String <optional>
ret me.Rect <optional>
a object in which to store the text metrics
Source:
bitmaptext.js, line 206
Returns:
a TextMetrics object with two properties: `width` and `height`, defining the output dimensions
Type
TextMetrics

<static> resize(scale)

change the font display size
Parameters:
Name Type Description
scale Number ratio
Source:
bitmaptext.js, line 189
Returns:
this object for chaining

<static> set(textAlign, scale)

change the font settings
Parameters:
Name Type Argument Description
textAlign String ("left", "center", "right")
scale Number <optional>
Source:
bitmaptext.js, line 148
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
Source:
bitmaptext.js, line 168
Returns:
this object for chaining