2012-12-05 49 views
0

如果我創建一個行...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不工作...

感謝

回答

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); 
    }); 
+0

的getX和的getY是我所追求的,但我如何得到的x和y隊伍的盡頭?我猜這是給出了開始位置的x和y?或者是偏移量? –

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(); 
    });