Canvas drawImage - visible edges of tiles in firefox/opera/ie (not chrome)

前端 未结 4 1043
自闭症患者
自闭症患者 2020-12-11 19:53

I\'m drawing a game map into canvas. The ground is made of tiles - simple 64x64 png images.

When I draw it in Chrome, it looks ok (left), but when I draw it in Firef

4条回答
  •  悲&欢浪女
    2020-12-11 20:32

    In every tile draw use Math.floor when there is division involved, like this:

        ctx.drawImage(image,Math.floor(xpos/3),ypos+1)
    

    Also, if you have a loop to draw, that calls itself, always use requestAnimationFrame. I don't know why, but since I moved from timer timeout to requestAnimationFrame I have no more artifacts.

提交回复
热议问题