Search code examples
javascriptkineticjs

KineticJS version 5.1 Drawing a line with mouse


I am updating my application from KineticJS 4.3.3 to 5.1, I used the following to draw a line using the mouse. In 4.3.3 I used

stage.getMousePosition();

It works please see http://jsfiddle.net/hnabih/rrxjdbaq/1/

Since 5.1 does not support getMousePosition, I changed it to:

stage.getPointerPosition();

I also changed:

line.getPoints() to line.points()

I can draw lines, but the location is wrong. Please see http://jsfiddle.net/hnabih/vofsst14/. Would appreciate your suggestions.


Solution

  • You need to change all points usage API. In KineticJS v5 points is array of numbers [x1, y1, x2, y2, ...].

    So instead of

    points[1].x = bla;
    

    You have to write

    points[2] = bla;