简体   繁体   English

kineticjs - 如何从一条线上获得点数

[英]kineticjs - How to get points from a line

If I create a line...如果我创建一条线...

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

}); });

And I attach a event...我附上了一个事件...

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

How could I get the points back out?怎么才能把积分拿回来? this.attrs.points does not work... this.attrs.points不起作用...

You can get the points with line.getPoints() but they usually don't change after dragging and dropping, the X, Y coordinates change which the relative points are drawn from.您可以使用line.getPoints()获取点,但它们通常在拖放后不会改变,X、Y 坐标会改变,相对点是从中绘制的。 You can get those with line.getX() and line.getY()您可以使用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);
  });

I concur with nak but I would recommend:我同意 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();
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM