论文JS多维数组

时间:2013-06-04 21:55:05

标签: javascript paperjs

我已经使用paperJS创建了一个圆圈,现在我将为创建的圆圈应用撤消选项。那么如何将Point {x: 537, y: 157}(这是paperjs中的event.point)保存到数组中。任何帮助。

1 个答案:

答案 0 :(得分:2)

如果你想要从屏幕上删除这些项目,那就不像从数组中删除它们那么简单,因为它们仍然存储在children数组中,无论创建时它们处于什么状态?如果您没有更改图层,请project.activeLayer

以下代码创建三个不同颜色的圆圈,将它们存储在一个数组中,然后将第二个圆圈拼接出数组,最后将其从视图中移除(jsbin here):

<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
  <script type="text/javascript" src="https://raw.github.com/paperjs/paper.js/master/dist/paper.js"></script>
  <script type="text/paperscript" canvas="p">
    var circleArray = [];
    circleArray.push(new Path.Circle({
        center: [20, 20],
        radius: 10,
        strokeColor: 'red'
        }));
    circleArray.push(new Path.Circle({
        center: [30, 30],
        radius: 10,
        strokeColor: 'green'
        }));
    circleArray.push(new Path.Circle({
        center: [40, 40],
        radius: 10,
        strokeColor: 'blue'
        }));
    var idOfItemToRemove = 1;
    var numberOfItemsToRemove = 1;
    var removeItems = circleArray.splice(idOfItemToRemove, numberOfItemsToRemove);
    for (var i = 0; i < removeItems.length; i++) {
        removeItems[i].remove();
    }
  </script>
</head>
<body>
  <canvas id="p" resize></canvas>
</body>
</html>