我想获取点击NODE区域外的事件,有没有好的办法,求指教
给节点添加不规则碰撞组件,如何在节点挂载的脚本开头里写:
properties: {
collider: {
default: null,
type: cc.PolygonCollider,
},
type:-1,
},
在事件里写:
onTouchBegan: function (touch, event) {
var touchLoc=touch.getLocation(); if(!cc.Intersection.pointInPolygon(touchLoc,self.collider.world.points)){
console.log(“点击在外部”);
}else{
}
}
cc.find(“Canvas”).on(“touchstart”,e=>{})
type纯属多余,复制多了
cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
onTouchBegan: (touch, event) => {
var touchLoc = touch.getLocation();
var pos = self.itemParent.convertToNodeSpace(touchLoc);
if(pos.x>self.itemParent.width || pos.x<0 || pos.y>self.itemParent.height || pos.y < 0){
self.itemParent.active = false;
event.stopPropagation();
return false;
}
return true;
}
}, this.itemParent);