Constructor
new FontImage(imageopt, tileSizeopt, paddingSizeopt, contextopt)
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 |
context | CanvasRenderingContext2D | | <optional> | overlayContext | context to draw to |
- Source
Example
// use built in font
const font = new ImageFont;
// draw text
font.drawTextScreen("LittleJS\nHello World!", vec2(200, 50));
Methods
drawText(text, pos, scaleopt, centeropt)
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> |
- Source
drawTextScreen(text, pos, scaleopt, centeropt)
Draw text in screen space using the image font
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
text | String | |||
pos | Vector2 | |||
scale | Number | <optional> | 4 | |
center | Boolean | <optional> |
- Source