JavaScript Failed to execute 'drawImage'

后端 未结 2 1707
梦如初夏
梦如初夏 2020-12-15 04:23

Ok so I\'m creating a game with JavaScript Canvas Elements and such. I\'ve been able to load in TONS of Images, but on a select few, JavaScript replies with Errors such as <

相关标签:
2条回答
  • 2020-12-15 04:52

    you should wait all elements load,so do like this:

    window.onload=function(){
           board.drawImage(document.getElementById("player_explode"), this.x, this.y);
    }
    
    0 讨论(0)
  • 2020-12-15 05:05

    The problem was the way that I was loading my Images, I should've been doing:

    var image = new Image();
    image.src = "imagesource.jpg";
    

    But instead I was get the elements by id from the document page.

    Resources:

    Explanation on loading images

    Explanation on how html loads images

    0 讨论(0)
提交回复
热议问题