代码之家  ›  专栏  ›  技术社区  ›  ceremcem

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

  •  0
  • ceremcem  · 技术社区  · 6 年前

    就像我们一样 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() 这个 group Sketch

    1 回复  |  直到 6 年前
        1
  •  2
  •   ceremcem    6 年前

    原来它是由 applyMatrix: false 参数: Sketch

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