2021年2月7日星期日

Why is my Javascript canvas image not moving I see no error

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>
https://stackoverflow.com/questions/66094684/why-is-my-javascript-canvas-image-not-moving-i-see-no-error February 08, 2021 at 08:57AM

没有评论:

发表评论