Namespace

Text

Text

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.

View Source rpgcode.js, line 1001

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

View Source rpgcode.js, line 2201

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.

View Source rpgcode.js, line 2921

Example
// Set the global font to 8px Lucida Console
rpgcode.setFont(8, "Lucida Console");
  

Type Definitions

Object

# TextDimensions

Properties:
Name Type Description
width number
height number

View Source rpgcode.js, line 3574