Constructor
new ImageFont(tileInfo)
Create an image font
Parameters:
| Name | Type | Description |
|---|---|---|
tileInfo | TileInfo | Tile info of first character in font |
- Source
Example
// use built in font
const font = engineImageFont;
// draw text
font.drawTextScreen('LittleJS\nHello World!', vec2(200, 50), 16);Members
tileInfo
Properties| Type | Description |
|---|---|
| TileInfo | Tile info for the font |
- Source
Methods
drawText(text, pos, sizeopt, centeropt, coloropt, useWebGLopt, contextopt)
Draw text in world space using the image font
- The text stays upright and ignores cameraAngle, each glyph is snapped to whole screen pixels to keep it crisp
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
text | string | | |||
pos | Vector2 | |||
size | Vector2 | | <optional> | 1 | |
center | boolean | <optional> | true | center each line on pos, and the lines of multi-line text around it |
color | Color | <optional> | WHITE | |
useWebGL | boolean | <optional> | glEnable | |
context | CanvasRenderingContext2D | | <optional> |
- Source
drawTextScreen(text, pos, size, centeropt, coloropt, useWebGLopt, contextopt)
Draw text in screen space using the image font
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
text | string | | |||
pos | Vector2 | |||
size | Vector2 | | |||
center | boolean | <optional> | true | center each line on pos, and the lines of multi-line text around it |
color | Color | <optional> | WHITE | |
useWebGL | boolean | <optional> | glEnable | |
context | CanvasRenderingContext2D | | <optional> |
- Source
getGlyphPos(index, posopt) → {Vector2}
Get where a glyph sits in the texture: counted in the font's own columns when its tile has them, like a font packed by loadSprite, otherwise along the texture's grid from the font's first tile, the way tile() lays it out
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
index | number | Glyph number, 0 is the space and the characters follow in ASCII order | |
pos | Vector2 | <optional> | Written into and returned, for a loop that places many |
- Source
Returns:
- Type:
- Vector2