觉醒时刻
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.
juexingshike/assets/Scripts/NewGuide/NewGuideScript.ts

140 lines
3.7 KiB

1 week ago
// Learn TypeScript:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
import Common5 from "../../Platform/th/Common5";
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewGuideScript extends cc.Component {
@property(cc.Mask)
maskNode: cc.Mask = null;
@property(cc.Node)
shouzhiNode: cc.Node = null;
isPlayAnim = true
nodeArray: cc.Node[] = [];
graphics = null
registNode = null
bindNode() {
//监听事件
this.node.on(cc.Node.EventType.TOUCH_START, (event) => {
//目标节点不存在,拦截
if (!this.registNode) {
this.node['_touchListener'].setSwallowTouches(true);
return;
}
//目标区域存在,击中放行
let rect = this.registNode.getBoundingBoxToWorld();
if (rect.contains(event.getLocation())) {
this.node['_touchListener'].setSwallowTouches(false);
cc.log('命中目标节点,放行');
this.registNode = null
if (this.nodeArray.length == 0) {
this.node.removeFromParent()
this.node.destroy()
} else {
let nextNode = this.nodeArray.shift()
this.nextNode(nextNode)
}
} else {
this.node['_touchListener'].setSwallowTouches(true);
cc.log('未命中目标节点,拦截');
}
}, this);
}
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
onLoad() {
this.graphics = this.maskNode['_graphics']
this.bindNode()
}
nextNode(registNode) {
this.registNode = registNode
let posi = Common5.getNodeToTargetPos(this.shouzhiNode, registNode)
if (this.isPlayAnim) {
// this.shouzhiNode.setPosition(0, 0)
cc.tween(this.shouzhiNode)
.to(0.6, { x: posi.x + 50, y: posi.y - 50 })
.call(() => {
this._focusToNode(registNode)
})
.start()
} else {
this.shouzhiNode.setPosition(posi.x + 50, posi.y - 50)
this._focusToNode(registNode)
}
}
setBindNode(registNode, nodeArray) {
this.registNode = registNode
this.nodeArray = nodeArray
let posi = Common5.getNodeToTargetPos(this.shouzhiNode, registNode)
if (this.isPlayAnim) {
// this.shouzhiNode.setPosition(0, 0)
cc.tween(this.shouzhiNode)
.to(0.6, { x: posi.x + 50, y: posi.y - 50 })
.call(() => {
this._focusToNode(registNode)
})
.start()
} else {
this.shouzhiNode.setPosition(posi.x + 50, posi.y - 50)
this._focusToNode(registNode)
}
}
_focusToNode(node) {
console.log('挖洞++++++++++======')
this.graphics.clear();
let rect = node.getBoundingBoxToWorld();
this.maskNode.node.setContentSize(0, 0)
let p = this.node.convertToNodeSpaceAR(rect.origin);
rect.x = p.x;
rect.y = p.y;
Common5.setNodeToTargetPos(this.maskNode.node, node)
this.maskNode.node.setContentSize(rect.width + 50, rect.height + 50)
// //roundRect
// this.graphics.fillRect(rect.x, rect.y, rect.width+20, rect.height+20);
// return rect;
}
// update (dt) {}
}