kineticjs - 如何从一条线上获得积分

时间:2012-12-05 21:26:18

标签: javascript-events kineticjs

如果我创建一条线......

 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不起作用......

由于

2 个答案:

答案 0 :(得分: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);
  });

答案 1 :(得分: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();
  });