Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Fabric.js坐标对象的中心_Javascript_Graphics_Fabricjs - Fatal编程技术网

Javascript Fabric.js坐标对象的中心

Javascript Fabric.js坐标对象的中心,javascript,graphics,fabricjs,Javascript,Graphics,Fabricjs,我在玩我的0,0点,因为我想在我以后的工作中每次都有它的坐标。 直到我使用addWithUpdate,并且只使用add-一切都很好:我有我的0,0分。但边界也是-零点。 当我使用addWithUpdate时-我的0,0分丢失 例如,我想使用 this.graphics = new fabric.Group(); this.graphics.add(new fabric.Circle({ left: -2.25, top: -2.25, radius: 4.5, fill: 'li

我在玩我的0,0点,因为我想在我以后的工作中每次都有它的坐标。 直到我使用addWithUpdate,并且只使用add-一切都很好:我有我的0,0分。但边界也是-零点。 当我使用addWithUpdate时-我的0,0分丢失

例如,我想使用

this.graphics = new fabric.Group();
this.graphics.add(new fabric.Circle({
  left: -2.25,
  top: -2.25,
  radius: 4.5,
  fill: 'lime',
  hasBorders: false
}));
this.graphics.addWithUpdate(new fabric.Rect({
  left: 0,
  top: 0,
  width: 30,
  height: 4.5,
  fill: 'lime',
  hasBorders: false
}));
在50,50中没有物体的左上角,而是圆的中心(因为它是我的0,0点)


我该怎么做?可以从文档中指定对象的定位点,或类似的东西?

对象的左:
左位置。请注意,默认情况下,它是相对于对象中心的。您可以通过设置originX={left/center/right}
来更改此设置。所以将对象的originX和originY设置为
center
Yep,但问题是设置originX/Y center会指向组的数学中心,就像边界矩形的中心一样。但是我需要我自己的锚,指向我想要的任何地方,更重要的是,当我向组中添加一些对象时(如果您向组中添加新对象-math.center moves),锚不会改变。就好像我想得到自己的合作。每个组的系统。例如,首先组只包含圆,然后中心位于圆的中心。在此之后,在上一个圆的左侧添加另一个半径相同的圆将使圆心移动到圆交点。所以我需要这个点,它在添加过程中不会移动。顺便说一句,我不是
fabric.js
用户,但在我看来,您可以简单地使用一些对象属性扩展
this.graphics
,这些属性存储对原始X/Y原点的引用(例如
this.graphics.ancorpoint={x:this.graphics.left,y:this.graphics.top}
,或一个函数,它重新计算并在每次添加新元素时触发。。
this.graphics.set('left', 50);
this.graphics.set('top', 50);