Saturday, 16 July 2011

Snippet - Draw Text to HTML5 Canvas

This function draws text to the canvas with a specified position, color and font.
function drawCanvasText(txt, pX, pY, clr, fnt) {
 context2D.fillStyle = clr; // color
 context2D.font = fnt; // font
 context2D.fillText(txt, pX, pY); // text at position X, Y
}


Example Usage:
drawCanvasText("drawing text yas", 50, 50, "black", "bold 30px sans-serif");