I am using the following to get the mouse position:
var coordinate = 0;
............
canvas1.addEventListener('mousemove', function (evt) {
var mousePos = getMousePos(canvas1, evt);
var nY = Math.round(mousePos.y);
var nX = Math.round(mousePos.x);
coordinate = "x=" + nX + ", y=" + nY;
$('#pValue').val(coordinate);
}, false);
It works great if I display the value in a text field; however I could not update a text layer:
dlayerA1Text = new Kinetic.Layer();
var simpleTextRight = new Kinetic.Text({
x: lOffset + (lOffset * 0.25),
y: 15,
text: coordinate,
fontSize: 12,
fontFamily: 'Calibri',
fill: 'white',
align: 'left'
});
This was very helpful. However, the latest version of kinetic.js no longer has 'getMousePosition', they are using the 'getPointerPosition'.
Which is nice, because I could not get hand.js to work with kinetic.js. Appears they already thought of that.
[Edited – again! Sorry about my incomplete answer last night – I was sleepy!]
To get a Kinetic Text to display coordinates of mouse movements on the stage…
The stage itself does not emit mouse events, but we can use
stage.getContent
to get the stage’s DIV so we can listen for mouse events on that div:Then in the onMousemove handler, we can get the coordinate of the mouse on the stage:
And finally we update the kinetic text to show that coordinate:
Here is code and a Fiddle: http://jsfiddle.net/m1erickson/KamDV/