擦除部分运动图像

时间:2013-04-09 12:46:36

标签: javascript html5

有没有办法只清除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>

1 个答案:

答案 0 :(得分:2)

简单的答案是否定的。画布是平面位图,而不是对象的分层集合。一旦你画到它就会失去你画画背后的背景。

您可以尝试自己实现功能,首先记录用于创建画布的步骤,然后使用或不使用相关图像重新创建它。

相关问题