我智商爆棚
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.
 
 
 
 
 

131 lines
3.5 KiB

//影子拖动move事件
import { ryw_Event } from "../../FrameWork/Event/EventEnum";
import EventMgr from "../../FrameWork/Event/EventMgr";
import GameReport from "../../FrameWork/Report/ZyZyReport";
import Common5 from "../../Platform/th/Common5";
const { ccclass, property } = cc._decorator;
@ccclass
export default class MoveTouchScript extends cc.Component {
@property(cc.Node)
touchNode: cc.Node = null;
@property(cc.Node)
MoveNode: cc.Node = null; //设计??
@property(cc.Boolean)
isPlayAnim: Boolean = false; //设计??
@property(cc.String)
playAnim: String = ''; //设计??
onLoad() {
if (!this.touchNode) {
this.touchNode = this.node
}
if (!this.MoveNode) {
this.MoveNode = this.node
}
}
setTouchNode(checkNode, targetNode) {
this.initTouchEvent(this.touchNode, checkNode, targetNode)
}
initTouchEvent(node, checkNode, targetNode) {
var attrs = {
checkNode: checkNode,
recoveposi: node.getPosition(),//初始位置
targetNode: targetNode,
};
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
}
touchMoveNode(event) {
let posi = event.getLocation()//世界坐标
let target = event.target
posi = target.parent.convertToNodeSpaceAR(posi)
target.setPosition(posi)
}
touchEndNode(event) {
let target = event.target
if (Common5.checkIntersectsBox(target, target.checkNode)) {
Common5.playEffect('点击音效')
target.active = false
target.targetNode.active = true
target.checkNode.active = false
//呼吸动画
if (target.targetNode.getChildByName('noAnim')) {
} else {
cc.tween(target.targetNode)
.to(2, { scaleY: 0.99 })
.to(2, { scaleY: 1.01 })
.union()
.repeatForever()
.start()
}
GameReport.BtnsReport("人影" + target.roleName, Common5.selectGameInfo.titleUrl);
console.log("[GameReport]++++++++++++++++++++++>" + "人影" + target.roleName);
EventMgr.emitEvent_custom(ryw_Event.touchMoveCheck, { targetNode: target.targetNode })
console.log('checkNode++++++++++true')
} else {
if (target["recoveposi"]) {
this.nodeMoveToRecovery(target, target["recoveposi"])
}
}
//
}
nodeMoveToRecovery(node, oldPosi: cc.Vec2, func?: Function) {
cc.tween(node)
.to(0.1, { x: oldPosi.x, y: oldPosi.y })
.call(() => {
if (func) {
func()
}
})
.start()
}
// update (dt) {}
}