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

私はナクに同意しますが、お勧めします:

 //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 に答える