2013-04-05 53 views
0

我可以在畫布上繪製多行;它們被添加到使用drawScene的圖層繪製多行並刪除單行

dlayerA1.add(line); 
line.getPoints()[0].x = mousePos.x; 
line.getPoints()[0].y = mousePos.y; 
line.getPoints()[1].x = mousePos.x; 
line.getPoints()[1].y = mousePos.y; 
moving = true; 
dlayerA1.drawScene(); 

http://jsfiddle.net/user373721/xzEad/1/

有沒有辦法刪除單行?

回答

0

我分配一個唯一的ID到每個對象,並用於以下操作來DELET它當點擊它:

      r = r + 1; 
         var mousePos = stage1.getMousePosition(); 
         rectA1 = new Kinetic.Rect({ 
          x: mousePos.x - rOffset, 
          y: mousePos.y - rOffset, 
          width: 0, 
          height: 0, 
          stroke: 'red', 
          strokeWidth: 4, 
          id:"rectA" + r 
          }); 

         rectA1.setListening(true); 
         myRect1[r] = rectA1; 
         background1.add(myRect1[r]); 
         //start point and end point are the same 
         rectA1.setX(mousePos.x - rOffset); 
         rectA1.setY(mousePos.y - rOffset); 
         rectA1.setWidth(0); 
         rectA1.setHeight(0); 
         moving = true; 

         background1.drawScene(); 
         myRect1[r].on("click", function() { 

          this.remove(); 
         }); 

我的解決方案是基於這個好答案:How to select an object in kinetic.js?

0

目前,你就必須修改點陣列是這樣的:

line.getPoints()[0] .splice(指數,1);

由於陣列通過參考修改,修改返回的數組修改點陣列「真實的源」 ATTR

+0

感謝埃裏克,有一個例子某處我看看。 – hncl 2013-04-06 00:53:01