2014-04-28 29 views
0

我用kineticjs畫了兩個圓, 我想對稱地改變第一個圓的dragmove上的圓的位置,這是我的代碼。在dragmove上對稱地改變圓的位置kineticjs的另一個圓

newArc = new Kinetic.Circle({ 
      x: mouse.x, 
      y: mouse.y, 
      radius: .25, 
      fill: Color, 
      stroke: "lightgray", 
      strokeWidth: 3, 
      draggable: true 
     }); 
     layer.add(newArc); 

     newArcMir = new Kinetic.Circle({ 
      x: stage.getWidth()-mouse.x, 
      y: mouse.y, 
      radius: .25, 
      fill: Color, 
      stroke: "lightgray", 
      strokeWidth: 3, 
      draggable: true 
     }); 
     newArc.on('dragmove', function() { 
     newArcMir.setX(stage.getWidth()-this.getX()); 
     newArcMir.setY(this.getY()); 
    }); 
    newArcMir.on('dragmove', function() { 
     newArc.setX(stage.getWidth()-this.getX()); 
     newArc.setY(this.getY()); 
    }); 

我得到一個錯誤「遺漏的類型錯誤:無法讀取屬性‘中與此相關的行

newArcMir.setX(stage.getWidth()-this.getX()); 
+0

你可以做任何jsfidle演示? – lavrton

+0

這是jsfidle演示http://jsfiddle.net/D2vbd/ –

+0

你演示不工作,我的意思是它壞了。 – lavrton

回答

0

我的問題解決了鍍鉻’空的」 setX的,它與JS的全局變量相關, kenetic不接受他們,不能用setX或setY作爲全局變量。

,所以我創建了一個局部變量,我把他們當作遵循

    var drawTextTest = newArcMir; 
        var newArc2 = newArc; 
     newArc.on('dragmove', function() { 

     drawTextTest.setX(stage.getWidth()-this.getX()); 
     drawTextTest.setY(this.getY()); 
        }); 

    newArcMir.on('dragmove', function() { 

       newArc2.setX(stage.getWidth()-this.getX()); 
      newArc2.setY(this.getY()); 


    }); 
相關問題