Constructor
new FontImage(imageopt, tileSizeopt, paddingSizeopt)
Create an image font
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
image | HTMLImageElement | <optional> | Image for the font, if undefined default font is used | |
tileSize | Vector2 | <optional> | (8,8) | Size of the font source tiles |
paddingSize | Vector2 | <optional> | (0,1) | How much extra space to add between characters |
- Source
Example
// use built in font
const font = new FontImage;
// draw text
font.drawTextScreen('LittleJS\nHello World!', vec2(200, 50));
Methods
drawText(text, pos, scaleopt, centeropt, contextopt)
Draw text in world space using the image font
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
text | string | |||
pos | Vector2 | |||
scale | number | <optional> | .25 | |
center | boolean | <optional> | ||
context | CanvasRenderingContext2D | | <optional> | drawContext |
- Source
drawTextOverlay(text, pos, scaleopt, centeropt)
Draw text on overlay canvas in world space using the image font
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
text | string | |||
pos | Vector2 | |||
scale | number | <optional> | 4 | |
center | boolean | <optional> |
- Source
drawTextScreen(text, pos, scaleopt, centeropt, contextopt)
Draw text on overlay canvas in screen space using the image font
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
text | string | |||
pos | Vector2 | |||
scale | number | <optional> | 4 | |
center | boolean | <optional> | ||
context | CanvasRenderingContext2D | | <optional> | drawContext |
- Source