HTML5 Game - Rendering Text in Canvas

Description

Rendering Text in Canvas

Demo

ResultView the demo in separate window

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Canvas Demo</title> 
        <style> 
canvas { /*from ww w  . j  a  va  2 s . co  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');  
  
myContext.font = '35px sans-serif'; 
myContext.strokeStyle = '#000'; 
myContext.lineWidth = 2; 
myContext.textAlign = 'center'; 
myContext.strokeText('Hello World', 100, 100); 
      </script> 
    </body> 
</html>

Related Topic