绘制多行并删除单行

时间:2013-04-05 18:41:54

标签: draw kineticjs

我可以在画布上画多条线;它们使用drawScene

添加到图层中
dlayerA1.add(line);
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;
dlayerA1.drawScene();

http://jsfiddle.net/user373721/xzEad/1/

有没有办法删除单行?

2 个答案:

答案 0 :(得分:0)

目前,你必须像这样修改点数组:

line.getPoints()[0] .splice(index,1);

由于数组是通过引用修改的,修改返回的数组会修改“事实来源”点数组attr

答案 1 :(得分:0)

我为每个对象分配了一个唯一的ID,并在点击它时使用以下内容删除它:

                         r = r + 1;
                        var mousePos = stage1.getMousePosition();
                        rectA1 = new Kinetic.Rect({
                            x: mousePos.x - rOffset,
                            y: mousePos.y - rOffset,
                            width: 0,
                            height: 0,
                            stroke: 'red',
                            strokeWidth: 4,
                            id:"rectA" + r
                          });

                        rectA1.setListening(true);
                         myRect1[r] = rectA1;
                        background1.add(myRect1[r]);
                        //start point and end point are the same
                        rectA1.setX(mousePos.x - rOffset);
                        rectA1.setY(mousePos.y - rOffset);
                        rectA1.setWidth(0);
                        rectA1.setHeight(0);
                        moving = true;

                        background1.drawScene();
                        myRect1[r].on("click", function () {  

                            this.remove();
                        });

我的解决方案基于这个好的答案:How to select an object in kinetic.js?