我成功地将带有尾部的移动(可见)路径编码为- https://www.kirupa.com/canvas/follow_mouse_cursor.htm
但是当我用ctx.clip()替换ctx.fill()时,什么也看不到……这是我的JavaScript代码–请参见https://codepen.io/j-raff/pen/JQxOPj
的完整代码var jrCanvas = document.getElementById("jr-canvas");
var ctx = jrCanvas.getContext("2d");
var mouseX, mouseY;
var bgImageOnCanvas = new Image();
bgImageOnCanvas.src =
"http://www.graffik.de/wp-content/uploads/forgethers-abgesang-01.png";
bgImageOnCanvas.onload = function() {
ctx.drawImage(bgImageOnCanvas, 0, 0);
};
jrCanvas.addEventListener("mousemove", function(e){
mouseX = e.clientX;
mouseY = e.clientY;
}, false);
function update() {
ctx.save();
ctx.beginPath();
ctx.arc(mouseX, mouseY, 50, 0, Math.PI * 2, true);
ctx.clip();
requestAnimationFrame(update);
}
update();
答案 0 :(得分:0)
与此同时我解决了这个问题:)
请参见https://codepen.io/j-raff/pen/zVepOK
var jrCanvas = document.getElementById("jr-canvas");
var ctx = jrCanvas.getContext("2d");
var mouseX, mouseY;
var x, y;
var bgImageOnCanvas = new Image();
bgImageOnCanvas.src =
"http://www.graffik.de/wp-content/uploads/forgethers-abgesang-01.png";
jrCanvas.addEventListener("mousemove", function(e){
mouseX = e.clientX;
mouseY = e.clientY;
update();
}, false);
function update() {
ctx.save();
ctx.beginPath();
ctx.arc(mouseX, mouseY, 50, 0, Math.PI * 2, true);
ctx.clip();
ctx.drawImage(bgImageOnCanvas, 0, 0);
ctx.restore();
}