簡體   English   中英

kineticjs - 如何從一條線上獲得點數

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

如果我創建一條線...

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

您可以使用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);
  });

我同意 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