You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.6 KiB
97 lines
2.6 KiB
1 week ago
|
import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
|
||
|
import EventMgr from "../../../FrameWork/Event/EventMgr";
|
||
|
import Common5 from "../../../Platform/th/Common5";
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
const { ccclass, property } = cc._decorator;
|
||
|
|
||
|
@ccclass
|
||
|
export default class GoodMoveTouchScript2 extends cc.Component {
|
||
|
@property(cc.Node)
|
||
|
emitArea: cc.Node = null;
|
||
|
|
||
|
@property(cc.Node)
|
||
|
rightArea1: cc.Node = null;
|
||
|
|
||
|
@property(cc.Node)
|
||
|
rightArea2: cc.Node = null;
|
||
|
|
||
|
@property({
|
||
|
displayName: '是否隐藏物品'
|
||
|
})
|
||
|
isHideNode: boolean = false
|
||
|
|
||
|
copyNode:cc.Node = null
|
||
|
|
||
|
onLoad() {
|
||
|
this.initTouchEvent(this.node, this.emitArea)
|
||
|
|
||
|
}
|
||
|
|
||
|
initTouchEvent(node, emitArea) {
|
||
|
var attrs = {
|
||
|
emitArea: emitArea,
|
||
|
recoveposi: node.getPosition()//初始位置
|
||
|
};
|
||
|
node.attr(attrs);
|
||
|
this.openTouchEvent(node)
|
||
|
}
|
||
|
|
||
|
|
||
|
openTouchEvent(node) {
|
||
|
node.on(cc.Node.EventType.TOUCH_START, this.touchStartNode, this)
|
||
|
node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this)
|
||
|
node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this)
|
||
|
node.on(cc.Node.EventType.TOUCH_END, this.touchEndNode, this)
|
||
|
}
|
||
|
closeTouchEvent(node: cc.Node) {
|
||
|
node.off(cc.Node.EventType.TOUCH_START, this.touchStartNode, this)
|
||
|
node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this)
|
||
|
node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this)
|
||
|
node.off(cc.Node.EventType.TOUCH_END, this.touchEndNode, this)
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
touchStartNode(event) {
|
||
|
let target = event.target
|
||
|
this.copyNode = cc.instantiate(target)
|
||
|
this.copyNode.parent = target.parent
|
||
|
// Common5.playEffect('点击音效')
|
||
|
}
|
||
|
|
||
|
touchMoveNode(event) {
|
||
|
|
||
|
let posi = event.getLocation()//世界坐标
|
||
|
let target = event.target
|
||
|
posi = target.parent.convertToNodeSpaceAR(posi)
|
||
|
this.copyNode.setPosition(posi)
|
||
|
|
||
|
}
|
||
|
|
||
|
touchEndNode(event) {
|
||
|
|
||
|
let target = event.target
|
||
|
|
||
|
let isRight = false
|
||
|
if (Common5.checkIntersectsBox(this.copyNode, target.emitArea)) {
|
||
|
if(this.isHideNode){
|
||
|
this.node.active = false
|
||
|
}
|
||
|
if (this.rightArea1 && Common5.checkIntersectsBox(this.copyNode, this.rightArea1)) {
|
||
|
isRight = true
|
||
|
}else if (this.rightArea2 && Common5.checkIntersectsBox(this.copyNode, this.rightArea2)) {
|
||
|
isRight = true
|
||
|
}
|
||
|
EventMgr.emitEvent_custom(ryw_Event.goodTouchMoveCheck, this.node,isRight)
|
||
|
}
|
||
|
this.copyNode.removeFromParent()
|
||
|
}
|
||
|
|
||
|
|
||
|
// update (dt) {}
|
||
|
}
|