1

如此处发现: KineticJS - 用鼠标画线

KineticJs 非常适合绘制线条、形状和拖放它们。实际示例重绘总是同一条线,我想知道如何在舞台上绘制多条线(不再可编辑)以便将绘制导出为图像。

4

1 回答 1

4

您可以创建一个新行并将其添加到鼠标按下的图层中。

        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();            
            }

        });

检查演示:http: //jsfiddle.net/QTsgn/

于 2012-10-02T07:53:08.027 回答