我有一个纹理,我在剪切平面上使用drawImage()
。但是我遇到了一个问题,我无法弄清楚如何将其移动超过纹理的宽度,从而无限循环,但由于某种原因它也不会剪裁。重复纹理循环与剪辑()
我抽奖代码如下所示:
var radius = 120;
var pos = {'x':canvas.width/2,'y':canvas.height/2};
var x = 0;
var offsetX = 0;
function draw() {
ctx.clearRect(0,0,canvas.width,canvas.height);
x += 1.1415;
ctx.beginPath();
ctx.arc(pos.x, pos.y, radius, 0, Math.PI * 2, false);
ctx.closePath();
ctx.clip();
var scale = (radius * 2)/img.height;
ctx.drawImage(img, pos.x+x, pos.y, img.width, img.height, pos.x - radius - offsetX * scale, pos.y - radius, img.width * scale, img.height * scale);
ctx.restore();
requestAnimationFrame(draw);
}
我所创建的演示,你在这儿可以看到当纹理移动太远,会发生什么,就基本消失,我再次需要循环无间隙它之间的无缝:http://jsfiddle.net/dv2r8zpv/
什么是最好的方式来绘制纹理的位置,所以它会环绕,我不太明白如何做到这一点。
小提琴链路断开时 –
@固定尽管Kelv.Gonzales由于某种原因,你必须点击运行它启动。 – Sir