通过阅读有关包含点 ( http://fabricjs.com/docs/symbols/fabric.Canvas.html#containsPoint ) 的 Fabric 文档,它指出:
Applies one implementation of 'point inside polygon' algorithm
Parameters:
e
{ Event } event object
target
{ fabric.Object } object to test against
Returns:
{Boolean} true if point contains within area of given object
因此,基于此,我尝试遍历组内的所有对象,如果 containsPoint 返回 true,则选择该对象。
但它总是返回 false;
canvas.on('object:selected',function(o,i) {
console.log(o)
if ( o.target.isType('group') ) {
o.target.forEachObject(function(child) {
child.setCoords();
//always false
console.log(canvas.containsPoint(o.e, child) );
});
}
})
这是 jsFiddle - 有什么想法吗? http://jsfiddle.net/LNt2g/1/