How to move an image on the canvas?

前端 未结 1 1111
醉话见心
醉话见心 2021-01-26 18:46

I have this simple shooting canvas game which runs just fine. But my issue is that I want the image to do the shooting and not the blue rectangle? So how I can make my image mov

相关标签:
1条回答
  • 2021-01-26 19:05

    So it looks like you already have the image:

    var myImage = new Image();
    myImage.src = "pic.gif";
    

    Now you just need to redraw the image at the new position in the render function... so instead of using fixed position of 20,20, use the position based on variables:

    ctx.drawImage(myImage, this.x, this.y);
    
    0 讨论(0)
提交回复
热议问题