Drawing Text
Rendering text in regular HTML is easy, rendering text in an HTML5 Canvas is a little more involved but the effects that can be applied to text is greater than that of plain HTML and CSS. Here we show how to render some basic text using a variety of fonts, colors and font weights.
Firstly we set the font property, this property can contain the font name and size as well as the font weight, here we set it to Arial, 30px in size. The fillStyle controls how the text is painted onto the canvas, here we set it to a solid Red.
Finally we call the fillText method that does that actual text rendering, this method takes the text string to draw and the x and y position from the top-left of the canvas.
Gradient Fills
So far we could have displayed the above text using standard HTML and CSS, however when using the Canvas to draw text you have a whole lot more possibilities, one of these is the ability to apply gradients to text:
Here we create a vertical gradient that flows from dark Red to bright Red. For more details on using gradients and fill styles please see the Shapes and Fill Styles tutorial.
Measuring Text
A common requirement when dealing with text is to be able to measure how many pixels a block of text occupies. For this we can use the measureText() method that can be found on the graphics context:
This method returns a size object which contains the text dimensions.
Guide the car to its parking space in this fun Car Parking game.
Aim for the Trash Can and get the various items of Trash in the bin.
Fly your plane in this colorful vertical scrolling shoot-em-up. Blast the bad guys and collect any bonus's they leave behind.
Pop as many bubbles as possible in this fun and colorful bubble popping game. The levels start off easy enough but gradually get harder!
Here we have a bunch of monsters that need to be matched up. Look out for the bomb and spinning monsters that will cause special damage!
Guide your friendly Bird through the maze of pipes and other obstacles collecting the Stars in this cool arcade game inspired by the legendary Flappy Bird.
You are stranded on an Alien planet. Your goal is to build a space rocket and escape. Start by building units to create power and mine the metal patches. Build defenses to defend your base from the advancing Aliens and Zombies!
Play Pool against the computer or battle against your friends in the online mode!
Slice the fruit that is thrown up onto the screen. Slice the fruit into multiple pieces for maximum points!