I am trying to move my Image across the screen. I am using the html5 canvas element and I am using an Xpos var for the X position of the image. My image is loading fine... but when try to use the code I am about to show nothing happens it just sits there.... it gives me no error! Any ideas of what I am doing wrong? if so please let me know. Here's the code, Thanks
Xpos = Xpos + 5 document.addEventListener("keydown", keyPush) function keyPush(evt) { switch (evt.keyCode) { case 37: break; } } var canvas = document.getElementById("myCanvas") var ctx = canvas.getContext("2d") var imgPath = "Piskel.png" var imgObj = new Image() imgObj.src = imgPath imgObj.onload = function() { ctx.drawImage(imgObj, Xpos, 100, 100, 70) }
<canvas id="myCanvas" width="800" height="600"></canvas>
没有评论:
发表评论