2013-04-23 72 views
0

我遵循此示例:http://www.html5canvastutorials.com/labs/html5-canvas-modify-shape-color-on-click/爲了改變我的形狀在鼠標操作上的顏色。當設置填充時添加額外'嘈雜'像素

一切正常有關設置顏色,但看到例如:

我有一條藍線。當我將它翻譯爲紅色時,線條邊界上會保留一些藍色像素。當我回到藍色時,仍有一些紅色像素。

我的代碼如下:

recolor: function(newColor){ 
    // Children are Kinetic.rect or Kinetic.line 
    var children=this.group.children; 

    for(var k in children){ 

     if(children[k] instanceof Kinetic.Line) 
      children[k].setStroke(newColor); 
     else 
      children[k].setFill(newColor); 
    } 
    this.group.draw(); 
} 

下面是截圖(正常和縮放):

screenshot

+0

你有沒有在不同的瀏覽器中試過這個? – SoluableNonagon 2013-04-23 18:23:50

+0

是的,鉻和火狐。每個最新的 – 2013-04-23 18:32:17

回答

0

雖然我不知道發生了什麼,這將使這樣的錯誤,你可以試試這個:

recolor: function(newColor){ 
    // Children are Kinetic.rect or Kinetic.line 
    var children=this.group.children; 

    for(var k in children){ 

     if(children[k] instanceof Kinetic.Line) 
      children[k] = children[k].clone({stroke: newColor}); 
     else 
      children[k] = children[k].clone({fill: newColor}); 
    } 
    this.group.draw(); 
    this.group.getLayer().draw(); 
} 

這只是克隆喲ur對象,並將它們替換爲在config中有一個更改的對象。如果這不能解決你的問題,那麼kineticJS就不是問題。

+0

沒有解決問題。但我發現問題的原因。如果我調用layer.draw()而不是group.draw(),噪聲就會消失。我試着用其他非動態的例子。問題仍然存在。我會支持這個錯誤。 – 2013-04-23 23:43:01