0

对不起,我在fabric.js中使用PathGroup时遇到问题。我将三个对象添加到 PathGroup 并将此 PathGroup 添加到画布。然后我观察对象:选定事件。当用户选择三个对象之一时,我无法判断 e.memo.target 选择了哪一个(它引用了这个 PathGroup 对象)。我使用 PathGroup 是因为它更方便移动对象。我的示例代码如下:

canvas.observe('object:selected', function(e) {

              var objs = e.memo.target.getObjects();

              for(var i=0; i<objs.length; i++){
                  ...                    
                }
              }
            });  

感谢您的帮助!html5starter

4

1 回答 1

0

I thought something like this might work (if you're using >=0.7.1), but it doesn't :/

This would work if you operated with regular objects, not those inside the PathGroup (as they follow slightly different rules — being rendered relative to group itself, and have their coordinates relative to group as well).

canvas.observe('object:selected', function(e) {
  for (var objects = e.memo.target.getObjects(), i = objects.length; i--; ) {
    objects[i].setCoords();
    if (canvas.containsPoint(e.memo.e, objects[i])) {
      console.log(objects[i])  
    }
  }
});
于 2011-12-06T16:47:15.397 回答