Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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_Css_Canvas - Fatal编程技术网

Javascript 如何将图像放置在画布后面

Javascript 如何将图像放置在画布后面,javascript,html,css,canvas,Javascript,Html,Css,Canvas,我在游戏的最后阶段,当我放置背景图像时,它与画布重叠,我如何修复它谷歌翻译 将图像设置为包含画布的元素的css背景图像,或者使用比画布更小的z索引值将图像设置为绝对图像您可以使用画布的属性 var c=document.getElementById(“myCanvas”); var ctx=c.getContext(“2d”); var background=新图像(); background.src=”https://cdn0.iconfinder.com/data/icons/is_go

我在游戏的最后阶段,当我放置背景图像时,它与画布重叠,我如何修复它谷歌翻译


将图像设置为包含画布的元素的css背景图像,或者使用比画布更小的z索引值将图像设置为绝对图像

您可以使用画布的属性

var c=document.getElementById(“myCanvas”);
var ctx=c.getContext(“2d”);
var background=新图像();
background.src=”https://cdn0.iconfinder.com/data/icons/is_google_plus_one_icons/256/google_plus_one_-plus-1_canvas.png";
background.onload=函数(){
ctx.drawImage(背景,0,0,200,100);
ctx.moveTo(0,0);
ctx.lineTo(200100);
ctx.stroke();
}

在画布上设置背景。请将当前代码作为背景。我们看不出只有截图有什么问题。有太多的可能性生成您的描述和屏幕截图中显示的内容。我不知道CSS中有Z轴:谢谢!!