HTML5 Game - Rendering Text on Canvas

Description

Rendering Text on Canvas

Demo

ResultView the demo in separate window

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Canvas Demo</title> 
        <style> 
canvas { /*from   w ww.j a v a2s. c  o  m*/
  border: 1px solid #000; 
} 
        </style> 
    </head> 
    <body> 
      <canvas id="myCanvas" width="200" height="200">Did You Know: Every time 
        you use a browser that doesn't support HTML5
      </canvas> 
      <script> 
// Get the context we will be using for drawing. 
let myCanvas = document.getElementById('myCanvas'); 
let myContext = myCanvas.getContext('2d'); 
  
// Draw some text! 
myContext.font = '35px sans-serif'; 
myContext.strokeStyle = '#000'; 
myContext.strokeText('Hello World', 0, 40); 
myContext.textAlign = 'center'; 
myContext.fillStyle = 'rgba(200, 50, 25, 0.8)'; 
myContext.fillText('HTML5', 100, 100); 
      </script> 
    </body> 
</html>

Related Topic