Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing pathin real time using KineticJS
    text
    copied!<p>I want to draw a path on my canvas on the fly. I know how to do this is using following HTML5 canvas code:</p> <pre><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(); }); </code></pre> <p>My question is how do I accomplish the same thing using KineticJS.</p> <p>Update:</p> <p>I think something like this may work.</p> <pre><code> $('#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); }); }); </code></pre> <p>However, handling the beginPath() and moveTo(..) is proving to be problematic. I need to set these on a mousedown event. Any ideas?</p> <p>Update:</p> <p>The effect I am trying to get can be seen by selecting the pen option at <a href="http://www.redshiftsolutions.com/demos/whiteboard/whiteboard.html" rel="nofollow">http://www.redshiftsolutions.com/demos/whiteboard/whiteboard.html</a>. 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload