I have an index.html with the following code:
<!DOCTYPE html>
<html>
<head>
<title> HTML 5 - Airplane Game</title>
<link rel="stylesheet" href="gamestyle.css"/>
</head>
<body>
<canvas id="canvasBg">Your Browser does not support HTML5</canvas>
<script type="text/javascript" src="game.js"></script>
</body>
</html>
And a style in my css:
#canvasBg {
width: 800px;
height: 500px;
display: block;
margin: 100px auto;
background-color: #606060;
}
And here's my JS code:
var canvas = document.getElementById("canvasBg");
var ctxBg = canvasBg.getContext('2d');
var imgSprite = new Image();
imgSprite.src = "img/sprite.png";
window.addEventListener("load",init,false);
function init() {
ctxBg.drawImage(imgSprite,0,0,1600,500,0,0,1600,500);
}
Image to use: link
I would like to show only the scenario when calling the init
function. Why is not this happening?