canvas drawImage doesn't draw images the first time

前端 未结 1 1477
日久生厌
日久生厌 2020-12-11 18:13

I\'m working on a simple JavaScript game using HTML5 canvas. It\'s a very typical game-loop setup involving:

  • init() function that initializes objects to be use
相关标签:
1条回答
  • 2020-12-11 18:53

    I assume you are calling init() after the onload event of the window object is fired. The problem is, that does not guarantee to you that the image data is actually available at that point. AFAIR it would fire after the images are fetched from the network but then they still need to be decoded.

    Your best bet would be to wait for the images' onload event instead.

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