Module gamejs/font

Methods for creating Font objects which can render text to a Surface.


var font = new Font('20px monospace');
// render text - this returns a surface with the text written on it.
var helloSurface = font.render('Hello World')

Class Font

Instance Methods

Instance Properties

Font (fontSettings, backgroundColor)

Create a Font to draw on the screen. The Font allows you to render() text. Rendering text returns a Surface which in turn can be put on screen.


String fontSettings a css font definition, e.g., "20px monospace"
STring backgroundColor valid #rgb string, "#ff00cc"


Font.prototype.render (text, color)

Returns a Surface with the given text on it.


String text the text to render
String color a valid #RGB String, "#ffcc00"


gamejs.Surface Surface with the rendered text on it.

Font.prototype.size (text)

Determine the width and height of the given text if rendered with this Font.


String text the text to measure


Array the [width, height] of the text if rendered with this Font