Drawing with text
I agree, we've been working on some complicated things. Now, its time for us to lay back, kick off the shoes, and do something a bit easier.
Getting ready
The good news is, if you are on this page, you should already know the basics of getting a canvas up and running. So there isn't much more that you need to do besides picking the font, size, and position of your text.
Note
Here, we aren't covering how you can embed fonts that aren't created within JavaScript, but instead, via CSS, we will use a basic font and hope for the best in this sample.
How to do it...
In this example, we are going to create a text field. In this process, we are going to use gradients and shadows for the first time. Perform the following steps:
Gain access to the canvas 2D API:
var canvas = document.getElementById("textCanvas"); var wid = canvas.width; var hei = canvas.height; var context = canvas.getContext("2d");
Create a gradient style and fill the background with it:
var grd = context.createLinearGradient...