0

我可以在画布上画多条线;使用 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/

有没有办法删除个别行?

4

2 回答 2

0

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

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

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

于 2013-04-05T20:32:17.313 回答
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?

于 2013-05-18T05:03:54.260 回答