0

如果我创建一条线...

 var line = new Kinetic.Line({
  points: [0 , 5, 0, 100],
  stroke: 'black',
  strokeWidth: 2,
  draggable: true

});

我附上一个事件......

   line.on("mouseup", function () {
      updateLineInput( this.attrs.points );
   });

怎么才能把积分拿回来?this.attrs.points不工作...

4

2 回答 2

1

您可以获取点,line.getPoints()但它们通常在拖放后不会改变,X、Y 坐标会改变,相对点是从中绘制的。你可以得到那些line.getX()line.getY()

  //It would be better to use the 'dragend' event if you want it to fire on a drag/drop
  line.on('dragend', function() {

    //You may really want the coordinates too
    var x = line.getX();
    var y = line.getY();

    //But this is what you asked for:
    var points = line.getPoints();
    updateLineInput(points);
  });
于 2012-12-06T04:22:40.903 回答
1

我同意 nak 但我建议:

 //It would be better to use the 'dragend' event if you want it to fire on a drag/drop
  line.on('dragend', function(evt) {
     var myline=evt.shape;
    //You may really want the coordinates too
    var x = myline.getX();
    var y = myline.getY();

    //But this is what you asked for:
    var points = myline.getPoints();

    var mynewpoints=manipulate(points);
    myline.setPoints(mynewpoints);
    var mylayer=myline.getLayer();
    mylayer.draw();
  });
于 2012-12-06T07:46:52.583 回答