I want to draw a path on my canvas on the fly. I know how to do this is using following HTML5 canvas code:
$('#drawing-canvas').mousedown(function(e){
startx = e.pageX;
starty = e.pageY;
cxt.beginPath();
cxt.moveTo(startx,starty);
});
$('#drawing-canvas').mousemove(function(e){
cxt.lineTo(e.pageX,e.pageY);
cxt.strokeStyle='red';
cxt.lineWidth = 1;
cxt.stroke();
});
My question is how do I accomplish the same thing using KineticJS.
Update:
I think something like this may work.
$('#container').mousemove(function(e){
var pen = new Kinetic.Shape({
drawFunc: function(canvas) {
var context = canvas.getContext();
if(moving == false){ // grab the start xy coords from mousedown event
context.beginPath();
context.moveTo(startx,starty);
moving = true;
}
context.lineTo(e.pageX,e.pageY);
context.strokeStyle='#ff00ff';
context.lineWidth = 1;
context.stroke();
}
penlayer.add(pen);
stage.add(penlayer);
});
});
However, handling the beginPath() and moveTo(..) is proving to be problematic. I need to set these on a mousedown event. Any ideas?
Update:
The effect I am trying to get can be seen by selecting the pen option at http://www.redshiftsolutions.com/demos/whiteboard/whiteboard.html. This is a simple collaborative whiteboard that uses canvas and jQuery. I want to transition this to KineticJS because of the added drag and drop functionality.