我用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());
});
我收到错误'未捕获的TypeError:无法读取与此行相关的Chrome中属性'setX'的null'
newArcMir.setX(stage.getWidth()-this.getX());
答案 0 :(得分:0)
我解决了这个问题,它与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());
});