我有两个重叠的形状,我想在单击重叠时拖动它们。有一个简单的方法吗?
答案 0 :(得分:0)
这是一个小小的车,但你可以修改它,它做你要求的,只需要更多的逻辑/抛光。
您需要查看的主要代码是:
shapesLayer.on('mousedown', function(){
var userPos = stage.getUserPosition();
var intersected = shapesLayer.getIntersections(userPos); //gets all shapes intersecting at click position
for(var i = 0; i < intersected.length; i++) {
intersected[i].moveTo(group2); // moves intersected shapes to a new group , need to add some code so that when item is moved to new group it keeps it's position
}
group2.simulate('dragstart'); //simulate dragging
shapesLayer.draw();
});
shapesLayer.on('mouseup', function(){ //when mouse is released
var kids = group2.getChildren();
for(var i = 0; i < kids.length; i++) {
kids[i].moveTo(shapesLayer); //place back in original container
}
shapesLayer.draw();
});