由于是同事代码,而且是偶现,我在想可能无法定位出原因。
那就顺藤摸瓜查找问题。从拖拽处出发,松手后的判断作为入口。
然后发现很多人写的代码也就这个问题:
onLoad() {
this.worldPosition_ = this.node.parent.convertToWorldSpaceAR(this.node.position);
},
增加:这样在拖拽结束时,如果分辨率大小发生改变,worldPosition已经改变,但是重新计算了值,就不会有这个问题了。
isInHoleArea(dragNode) {
let dragCom = dragNode.getComponent(DRAGGABLE_ITEM_COM);
let worldP1 = dragCom.getWorldPosition()
if (this.useBB_) {
let bb = this.node.getBoundingBoxToWorld();
if (bb.contains(worldP1)) {
return true;
}
return false;
}
// 使用时再计算
this.worldPosition_ = this.node.parent.convertToWorldSpaceAR(this.node.position);
let dis = this.worldPosition_.sub(worldP1).mag();
return dis <= this.holeRadius_;
},