1

As found here: KineticJS - Drawing Lines with Mouse

KineticJs works great in order to draw lines, shapes and drag&drop them. The actual example redraw always the same line, i wonder how to draw multiple lines (no more editable) on the stage in order to export the draw as image.

Community
  • 1
  • 1
Michele
  • 1,468
  • 3
  • 24
  • 54

1 Answers1

4

You could create a new line and add it to the layer on mousedown.

        stage.on("mousedown", function(){
            if (moving){
                moving = false;layer.draw();
            } else {
                var mousePos = stage.getMousePosition();
                //CHANGED - Create new line
                line = new Kinetic.Line({
                    points: [0, 0, 50, 50],
                    stroke: "red"
                });
                //CHANGED - Add line to layer
                layer.add(line);
                //start point and end point are the same
                line.getPoints()[0].x = mousePos.x;
                line.getPoints()[0].y = mousePos.y;
                line.getPoints()[1].x = mousePos.x;
                line.getPoints()[1].y = mousePos.y;

                moving = true;    
                layer.drawScene();            
            }

        });

Check demo: http://jsfiddle.net/QTsgn/

Sev
  • 1,982
  • 1
  • 16
  • 27