Image flickers when mouse moves in HTML canvas

前端 未结 1 1975
走了就别回头了
走了就别回头了 2021-01-27 02:58

I already looked in these thread 1 and thread 2, but I still got the flickering when the mouse move.

My code:

    function draw(){
    var img = new Imag         


        
相关标签:
1条回答
  • 2021-01-27 03:38

    I'm assuming you're calling draw for each mousemove.

    Mousemove events occur about 30 times a second so there is not enough time to load an image inside a mousemove handler.

    Instead, load the image once at the start of your app.

    Then ctx.drawImage has enough time to draw that preloaded image during each mousemove event.

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