Methods
# drawText(x, y, text, canvasIdopt)
Draws the text on the canvas starting at the specified (x, y) position, if no
canvas is specified it defaults to the "renderNowCanvas".
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
number | The start position x in pixels. | ||
y |
number | The start postion y in pixels. | ||
text |
string | A string of text to draw. | ||
canvasId |
string |
<optional> |
renderNowCanvas | The ID of the canvas to draw onto. |
Example
// Display the text on the default canvas.
rpgcode.drawText(270, 300, "Hello world!");
rpgcode.renderNow();
// Display the text on a custom canvas.
var canvas = "myCanvas";
rpgcode.createCanvas(640, 480, canvas);
rpgcode.drawText(270, 300, "Hello world!", canvas);
rpgcode.renderNow(canvas);
# measureText(text) → {Text.TextDimensions}
Measures text as it would appear on a canvas using the current font, returning
the width and height of the text in pixels.
Parameters:
Name | Type | Description |
---|---|---|
text |
string |
An object containing the width and height of the text.
Example
var dimensions = rpgcode.measureText("Hello world");
rpgcode.log(dimensions.width);
rpgcode.log(dimensions.height);
# setFont(size, family)
Sets the engine's font to the specified size, and font family. Custom fonts
need to be installed on the user's system to work. For a list of builtin fonts
see: CSS Websafe Fonts
Parameters:
Name | Type | Description |
---|---|---|
size |
number | in pixels |
family |
string | E.g. Arial, Comic Sans, etc. |
Example
// Set the global font to 8px Lucida Console
rpgcode.setFont(8, "Lucida Console");