I wanted to know how do I put text on top of the image which is in the canvas. The image needs to be in the canvas since it is part of my game (Breakout). I get some text but it goes behind the image which is annoying.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Breakout</title>
</head>
<body bgcolor="#4d0000">
<p align="center">
<canvas id="canvas" width="1500" height="800" style="border:1px solid #d3d3d3;"></canvas>
</p>
<script>
window.onload = function(){
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var imageObj = new Image();
imageObj.onload = function(){
context.drawImage(imageObj, 0, 0);
context.font = "40pt Calibri";
context.fillText("BREAKOUT", 625, 100);
};
imageObj.src = 'C:/Users/study/Desktop/Breakout/Images/test3.jpg';
};
</script>
</body>
</html>