【问题标题】:html5 kineticjs draw multiple lineshtml5 kineticjs 绘制多条线
【发布时间】:2012-09-22 23:46:11
【问题描述】:

在这里找到: KineticJS - Drawing Lines with Mouse

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

【问题讨论】:

    标签: html canvas drawing kineticjs


    【解决方案1】:

    您可以创建一个新行并在 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();            
                }
    
            });
    

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

    【讨论】:

    • 这正是我所需要的,对不起,我是新的 tio kineticsjs :)
    猜你喜欢
    • 2012-10-22
    • 1970-01-01
    • 2017-06-13
    • 2016-01-23
    • 2014-08-20
    • 2020-04-22
    • 2019-08-31
    • 2013-03-08
    • 2019-10-27
    相关资源
    最近更新 更多