如何在Paper.js中相对于父组定位项目?

时间:2018-11-01 01:59:10

标签: paperjs

就像我们在CSS中进行position: relative;一样,我需要相对于父级Group定位所有新创建的项目。这是我期望得到的:

enter image description here

...具有以下代码:

var path = new Path([50, 0], [50, 100]);
var path2 = new Path([0, 50], [100, 50]);
// cross center at [50, 50]

var center = [100, 100]

var group = new Group({
    children: [path, path2],
    strokeColor: 'black'
});

// It's important to arrange the position 
// right after creating the group
group.translate([50, 50])

new Path.Circle({
    center: center,
    radius: 5,
    fillColor: 'red'
})

new Path.Rectangle({
    from: [10, 10],
    to: [40, 40],
    strokeColor: 'black',
    parent: group
})

但是,what I actually get is如下:

enter image description here

如何使新创建的项目相对于其父组定位?

  

注意:为了获取“所需”屏幕截图,我需要在插入矩形后.translate() groupSketch

1 个答案:

答案 0 :(得分:0)

事实证明,它受applyMatrix: false参数Sketch

的控制
var group = new Group({
    children: [path, path2],
    strokeColor: 'black',
    applyMatrix: false,
});
group.translate([50, 50])