0
有没有办法清除只有1个元素的画布(html5)?我在画布上有一个移动的图像,当我擦除图像时,背景颜色也一样。有没有办法只是删除图像,而不是整个背景。我的背景只是一个简单的颜色,但在未来它会更复杂。擦除部分运动图像
这也很棘手,因为没有办法从属性中获取图像x,y pos。
ClassLoadImages.prototype.m_move = function(){
this.x=++img1_x;
this.y=++img1_y;
//img1_x++;
//img1_y++;
// alert(img.x);
ctx.drawImage(img.imgElement, this.x, this.y);
// ctx.fillText("finished loading " ,10,40);
};
function doGameLoop() {
ctx.clearRect(0,0,600,400);
img.m_move();
if (img.x>30)
{
clearInterval(gameLoop);
}
}
var img= new ClassLoadImages('images/image4.jpg');
gameLoop = setInterval(doGameLoop, 100);
</script>
所以解决方案是重新绘制整个画布? – jagguy 2013-04-09 12:49:33
是的 - 我会这么说。除非你能弄清楚如何重绘你想要移除的图像后面的位。但无论哪种方式,都将由您来跟踪画布上的元素。 – 2013-04-09 12:50:24
@jagguy - 看看http://kineticjs.com/,看看它是否具备你想做的功能。我只是简单地看了一下,并将其加入书签供将来使用。 – 2013-04-09 12:51:50