2014-04-28 28 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()); 


    }); 
相关问题