Javascript 如何在Canvas js中用图像替换形状?
我正在尝试用一个图像文件替换下面的椭圆形状Javascript 如何在Canvas js中用图像替换形状?,javascript,image,canvas,litterallycanvas.js,Javascript,Image,Canvas,Litterallycanvas.js,我正在尝试用一个图像文件替换下面的椭圆形状 /* this is the image variable I'm trying to use to replace the shape*/ var img = new Image(); img.addEventListener('load', function(e) { canvas.drawImage(this, 0, 0, 400, 400); }, true); img.src="img/crystal.png"; /* this i
/* this is the image variable I'm trying to use to replace the shape*/
var img = new Image();
img.addEventListener('load', function(e) {
canvas.drawImage(this, 0, 0, 400, 400);
}, true);
img.src="img/crystal.png";
/* this is circle shape I'm trying to replace*/
stroke(0);
fill(175);
ellipse(xpos, ypos, 32, 32);
}
如果其他方法都不起作用,您可以尝试使用此方法。您的问题有点不清楚,您可以发布更多的代码吗?我不知道litterallycanvas.js,但是
stroke()
,fill()
和eliple()
是全局方法吗?你这样称呼他们吗?你想让你的图像填充椭圆形状,还是仅仅在与实际椭圆相同的位置?