如何正确绘制html5画布背景?

时间:2016-09-26 16:17:58

标签: html5 canvas

当我关闭背景图像时,我遇到了这个问题https://snag.gy/PRwJWD.jpg

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

在渲染任何游戏内容之前,请先清除画布。

// ctx is the 2d context and canvas is the canvas element
ctx.clearRect(0,0,canvas.width,canvas.height);

或者如果你想要一个设定的颜色,你可以使用

ctx.fillStyle = "#000000"; // black
ctx.fillRect(0,0,canvas.width,canvas.height);

这两种方法都会删除您获得的路径并通过硬件完成,因此非常快。

相关问题