Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将背景图像添加到Javascript“中”;“庞”;游戏_Javascript_Html_Canvas_Open Source_Pong - Fatal编程技术网

将背景图像添加到Javascript“中”;“庞”;游戏

将背景图像添加到Javascript“中”;“庞”;游戏,javascript,html,canvas,open-source,pong,Javascript,Html,Canvas,Open Source,Pong,作为我研究的一部分,我正在修改我在网上找到的一款开源“乒乓”游戏(由创建)中的一些部分 我想给游戏设置一个好的背景图像, 这不会影响游戏体验。 我尝试了很多方法,但到目前为止,Iv'e只成功地将背景颜色更改为不同的颜色,而不是实际图像: 尝试使用ctx.fillStyle来显示图像并不顺利,因为paintCanvas()不断循环,如果获得其他值,则一个“颜色”字符串(例如,一幅重500kb的背景图像)将在游戏中造成巨大延迟 有人有主意吗 谢谢,, 罗伊我觉得如果你在身体标签上放一张背景图片

作为我研究的一部分,我正在修改我在网上找到的一款开源“乒乓”游戏(由创建)中的一些部分

我想给游戏设置一个好的背景图像, 这不会影响游戏体验。
我尝试了很多方法,但到目前为止,Iv'e只成功地将背景颜色更改为不同的颜色,而不是实际图像:


尝试使用
ctx.fillStyle
来显示图像并不顺利,因为
paintCanvas()
不断循环,如果获得其他值,则一个“颜色”字符串(例如,一幅重500kb的背景图像)将在游戏中造成巨大延迟

有人有主意吗

谢谢,,
罗伊

我觉得如果你在身体标签上放一张背景图片就好了

<body background="someImage">
</body>

啊,对不起,我的朋友。我忘了在paintCanvas()中清除屏幕。更新答案!谢谢很有魅力
<body background="someImage">
</body>
// Function to paint canvas
function paintCanvas() {
    canvas.width = canvas.width; // Will clear the canvas
    //ctx.fillStyle = "blue";
    //ctx.fillRect(0, 0, W, H);
}