import { ryw_Event } from "../../../FrameWork/Event/EventEnum"; import EventMgr from "../../../FrameWork/Event/EventMgr"; import AppPlatform from "../../../FrameWork/Util/AppPlatform"; import Common from "../../../FrameWork/Util/Common"; import Common5 from "../../../Platform/th/Common5"; const { ccclass, property } = cc._decorator; enum MOVEDIR { UP, DOWN, LEFT, RIGHT, } @ccclass export default class CccGame { public static SpecilalShowNode: cc.Node = null; /** * 节点克隆触摸碰撞事件注册 * @param emitTarget 触发节点 * @param checkNode 触碰节点 * @param emitAttr 触发节点绑定参数 * @param allowCheckNode 允许触发节点,节点active为true触发 * @returns 回调函数集合 */ public static onCloneNodeTouchCheckEvent( emitTarget: cc.Node, checkNode: cc.Node, emitAttr: any = {}, allowCheckNode: cc.Node = null ) { //触碰回调事件 let completeCallback: (data_: any) => void = null; //克隆节点 let cloneNode = cc.instantiate(emitTarget); cloneNode.parent = emitTarget.parent; cloneNode.opacity = 0; //触摸开始 let touchStartNode = (event) => { Common5.playEffect("点击音效"); let target = event.target target.opacity = 255; console.log('touchStartNode', target.zIndex) let posi = event.getLocation()//世界坐标 posi = target.parent.convertToNodeSpaceAR(posi) target.setPosition(posi) EventMgr.emitEvent_custom(ryw_Event.openBGMove, { open: false }); }; //触摸移动 let touchMoveNode = (event) => { let target = event.target let posi = event.getLocation()//世界坐标 posi = target.parent.convertToNodeSpaceAR(posi) target.setPosition(posi) }; //触摸结束 let touchEndNode = (event) => { let target = event.target; let checkNode = target.checkNode; if (!allowCheckNode || allowCheckNode.active) { if (Common5.checkIntersectsBox(target, checkNode)) { if (completeCallback) { completeCallback({ targetNode: target }); } target.opacity = 0; } } if (target.recoveposi) { cc.tween(target) .to(0.2, { position: target.recoveposi }) .set({ opacity: 0 }) .start(); } }; //注册触摸事件 cloneNode['checkNode'] = checkNode; cloneNode['recoveposi'] = cloneNode.getPosition(); cloneNode.attr(emitAttr); cloneNode.on(cc.Node.EventType.TOUCH_START, touchStartNode) cloneNode.on(cc.Node.EventType.TOUCH_MOVE, touchMoveNode) cloneNode.on(cc.Node.EventType.TOUCH_CANCEL, touchEndNode) cloneNode.on(cc.Node.EventType.TOUCH_END, touchEndNode) //回调函数集合 let retFuncGroup = { /**设置完成后的事件监听 */ setCompleteListener: (callback: (data_: any) => void) => { completeCallback = callback; }, /**关闭触摸事件 */ closeTouchEvent: () => { cloneNode.off(cc.Node.EventType.TOUCH_START, touchStartNode); cloneNode.off(cc.Node.EventType.TOUCH_MOVE, touchMoveNode); cloneNode.off(cc.Node.EventType.TOUCH_CANCEL, touchEndNode); cloneNode.off(cc.Node.EventType.TOUCH_END, touchEndNode); completeCallback = null; } }; return retFuncGroup; } /** * 节点触摸碰撞事件注册 * @param emitTarget 触发节点 * @param checkNode 触碰节点 * @param emitAttr 触发节点绑定参数 * @param moveNode 触摸移动时的父节点 * @param allowCheckNode 允许触发节点,节点active为true触发 * @returns 回调函数集合 */ public static onNodeTouchClickAndCheckEvent( emitTarget: cc.Node, checkNode: cc.Node, emitAttr: any = {}, moveNode: cc.Node = null, allowCheckNode: cc.Node = null ) { //触碰回调事件 let checkCallback: (data_: any) => void = null; //点击回调事件 let clickCallback: (data_: any) => void = null; //是否属于点击 let isClick = false; //触摸开始 let touchStartNode = (event) => { let target = event.target; console.log('touchStartNode', target.zIndex); if (target['_touchListener']) { target['_touchListener'].setSwallowTouches(true); } Common5.playEffect("点击音效"); target.saveWorldPos = target.convertToWorldSpaceAR(cc.Vec2.ZERO); isClick = true; setTimeout(() => { isClick = false; }, 200); }; //触摸移动 let touchMoveNode = (event) => { let target = event.target if (moveNode) { target.parent = moveNode; } let posi = event.getLocation()//世界坐标 posi = target.parent.convertToNodeSpaceAR(posi) target.setPosition(posi) }; //触摸结束 let touchEndNode = (event) => { let target = event.target; if (target['_touchListener']) { target['_touchListener'].setSwallowTouches(false); } if (isClick) { target.active = false; if (clickCallback) { clickCallback({ targetNode: target }); } target.setPosition(target.recoveposi); target.parent = target.recoveparent; } else { let checkNode = target.checkNode; if (!allowCheckNode || allowCheckNode.active) { if (Common5.checkContainsNode(checkNode, target)) { target.active = false; checkNode.active = false; if (checkCallback) { checkCallback({ targetNode: target }); } } } if (target.recoveposi) { cc.tween(target) .to(0.2, { position: target.parent.convertToNodeSpaceAR(target.saveWorldPos) }) .set({ parent: target.recoveparent, position: target.recoveposi }) .start(); } } }; //注册触摸事件 emitTarget['checkNode'] = checkNode; emitTarget['recoveposi'] = emitTarget.getPosition(); emitTarget['recoveparent'] = emitTarget.parent; emitTarget.attr(emitAttr); emitTarget.on(cc.Node.EventType.TOUCH_START, touchStartNode) emitTarget.on(cc.Node.EventType.TOUCH_MOVE, touchMoveNode) emitTarget.on(cc.Node.EventType.TOUCH_CANCEL, touchEndNode) emitTarget.on(cc.Node.EventType.TOUCH_END, touchEndNode) //回调函数集合 let retFuncGroup = { /**设置完成后的事件监听 */ setCheckListener: (callback: (data_: any) => void) => { checkCallback = callback; }, /**设置完成后的事件监听 */ setClickListener: (callback: (data_: any) => void) => { clickCallback = callback; }, /**关闭触摸事件 */ closeTouchEvent: () => { emitTarget.off(cc.Node.EventType.TOUCH_START, touchStartNode); emitTarget.off(cc.Node.EventType.TOUCH_MOVE, touchMoveNode); emitTarget.off(cc.Node.EventType.TOUCH_CANCEL, touchEndNode); emitTarget.off(cc.Node.EventType.TOUCH_END, touchEndNode); checkCallback = null; clickCallback = null; } }; return retFuncGroup; } /** * 节点触摸碰撞事件注册 * @param emitTarget 触发节点 * @param checkNode 触碰节点 * @param emitAttr 触发节点绑定参数 * @param moveNode 触摸移动时的父节点 * @param allowCheckNode 允许触发节点,节点active为true触发 * @returns 回调函数集合 */ public static onNodeTouchCheckEvent( emitTarget: cc.Node, checkNode: cc.Node, emitAttr: any = {}, moveNode: cc.Node = null, allowCheckNode: cc.Node = null ) { //成功回调事件 let successCallback: (data_: any) => void = null; //失败回调事件 let failCallback: (data_: any) => void = null; //触摸开始 let touchStartNode = (event) => { let target = event.target; console.log('touchStartNode', target.zIndex); if (target['_touchListener']) { target['_touchListener'].setSwallowTouches(true); } Common5.playEffect("点击音效"); target.saveWorldPos = target.convertToWorldSpaceAR(cc.Vec2.ZERO); }; //触摸移动 let touchMoveNode = (event) => { let target = event.target if (moveNode) { target.parent = moveNode; } let posi = event.getLocation()//世界坐标 posi = target.parent.convertToNodeSpaceAR(posi) target.setPosition(posi) }; //触摸结束 let touchEndNode = (event) => { let target = event.target; if (target['_touchListener']) { target['_touchListener'].setSwallowTouches(false); } let checkNode = target.checkNode; if (!allowCheckNode || allowCheckNode.active) { if (Common5.checkContainsNode(checkNode, target)) { target.active = false; checkNode.active = false; if (successCallback) { successCallback({ targetNode: target }); } } else { if (failCallback) { failCallback({ targetNode: target }); } } } else { if (failCallback) { failCallback({ targetNode: target }); } } if (target.recoveposi) { cc.tween(target) .to(0.2, { position: target.parent.convertToNodeSpaceAR(target.saveWorldPos) }) .set({ parent: target.recoveparent, position: target.recoveposi }) .start(); } }; //注册触摸事件 emitTarget['checkNode'] = checkNode; emitTarget['recoveposi'] = emitTarget.getPosition(); emitTarget['recoveparent'] = emitTarget.parent; emitTarget.attr(emitAttr); emitTarget.on(cc.Node.EventType.TOUCH_START, touchStartNode) emitTarget.on(cc.Node.EventType.TOUCH_MOVE, touchMoveNode) emitTarget.on(cc.Node.EventType.TOUCH_CANCEL, touchEndNode) emitTarget.on(cc.Node.EventType.TOUCH_END, touchEndNode) //回调函数集合 let retFuncGroup = { /**设置完成后的事件监听 */ setSuccessListener: (callback: (data_: any) => void) => { successCallback = callback; }, /**设置完成后的事件监听 */ setFailListener: (callback: (data_: any) => void) => { failCallback = callback; }, /**关闭触摸事件 */ closeTouchEvent: () => { emitTarget.off(cc.Node.EventType.TOUCH_START, touchStartNode); emitTarget.off(cc.Node.EventType.TOUCH_MOVE, touchMoveNode); emitTarget.off(cc.Node.EventType.TOUCH_CANCEL, touchEndNode); emitTarget.off(cc.Node.EventType.TOUCH_END, touchEndNode); successCallback = null; failCallback = null; } }; return retFuncGroup; } /** * 节点触摸多碰撞事件注册 * @param emitTarget 触发节点 * @param checkNodeArray 触碰节点数组 * @param emitAttr 触发节点绑定参数 * @param moveNode 触摸移动时的父节点 * @returns 回调函数集合 */ public static onNodeTouchMoreCheckEvent( emitTarget: cc.Node, checkNodeArray: cc.Node[], emitAttr: any = {}, moveNode: cc.Node = null ) { //成功回调事件 let successCallback: (data_: any) => void = null; //失败回调事件 let failCallback: (data_: any) => void = null; //触摸开始 let touchStartNode = (event) => { let target = event.target; console.log('touchStartNode', target.zIndex); if (target['_touchListener']) { target['_touchListener'].setSwallowTouches(true); } Common5.playEffect("点击音效"); target.saveWorldPos = target.convertToWorldSpaceAR(cc.Vec2.ZERO); }; //触摸移动 let touchMoveNode = (event) => { let target = event.target if (moveNode) { target.parent = moveNode; } let posi = event.getLocation()//世界坐标 posi = target.parent.convertToNodeSpaceAR(posi) target.setPosition(posi) }; //触摸结束 let touchEndNode = (event) => { let target = event.target; if (target['_touchListener']) { target['_touchListener'].setSwallowTouches(false); } let checkNode = null; let checkNodeArray = target.checkNodeArray; for (let iterator of checkNodeArray) { if (this.SpecilalShowNode) { if (iterator == this.SpecilalShowNode) { if (iterator.active && Common5.checkContainsNode(iterator, target)) { checkNode = iterator; break; } } } else { if (iterator.active && Common5.checkContainsNode(iterator, target)) { checkNode = iterator; break; } } } if (checkNode) { target.active = false; checkNode.active = false; target['checkNode'] = checkNode; if (successCallback) { successCallback({ targetNode: target }); } } else { if (failCallback) { failCallback({ targetNode: target }); } } if (target.recoveposi) { cc.tween(target) .to(0.2, { position: target.parent.convertToNodeSpaceAR(target.saveWorldPos) }) .set({ parent: target.recoveparent, position: target.recoveposi }) .start(); } }; //注册触摸事件 emitTarget['checkNodeArray'] = checkNodeArray; emitTarget['recoveposi'] = emitTarget.getPosition(); emitTarget['recoveparent'] = emitTarget.parent; emitTarget.attr(emitAttr); emitTarget.on(cc.Node.EventType.TOUCH_START, touchStartNode) emitTarget.on(cc.Node.EventType.TOUCH_MOVE, touchMoveNode) emitTarget.on(cc.Node.EventType.TOUCH_CANCEL, touchEndNode) emitTarget.on(cc.Node.EventType.TOUCH_END, touchEndNode) //回调函数集合 let retFuncGroup = { /**设置完成后的事件监听 */ setSuccessListener: (callback: (data_: any) => void) => { successCallback = callback; }, /**设置失败后的事件监听 */ setFailListener: (callback: (data_: any) => void) => { failCallback = callback; }, /**关闭触摸事件 */ closeTouchEvent: () => { emitTarget.off(cc.Node.EventType.TOUCH_START, touchStartNode); emitTarget.off(cc.Node.EventType.TOUCH_MOVE, touchMoveNode); emitTarget.off(cc.Node.EventType.TOUCH_CANCEL, touchEndNode); emitTarget.off(cc.Node.EventType.TOUCH_END, touchEndNode); successCallback = null; failCallback = null; } }; return retFuncGroup; } /** * 节点单向移动碰撞事件注册 * @param emitTarget 触发节点 * @param checkNodeArray 触碰节点数组 * @param emitAttr 触发节点绑定参数 * @param directionMode 0水平,1垂直 * @param moveNode 触摸移动时的父节点 * @returns 回调函数集合 */ public static onNodeUnidirMoveCheckEvent( emitTarget: cc.Node, checkNodeArray: cc.Node[], emitAttr: any = {}, directionMode: number = 0, moveNode: cc.Node = null ) { //成功回调事件 let successCallback: (data_: any) => void = null; //失败回调事件 let failCallback: (data_: any) => void = null; //触摸开始 let touchStartNode = (event) => { let target = event.target; console.log('touchStartNode', target.zIndex); if (target['_touchListener']) { target['_touchListener'].setSwallowTouches(true); } Common5.playEffect("点击音效"); }; //触摸移动 let touchMoveNode = (event) => { let target = event.target if (moveNode) { target.parent = moveNode; } let posi = event.getLocation()//世界坐标 posi = target.parent.convertToNodeSpaceAR(posi) if (directionMode == 0) { target.x = posi.x; } else { target.y = posi.y; } }; //触摸结束 let touchEndNode = (event) => { let target = event.target; if (target['_touchListener']) { target['_touchListener'].setSwallowTouches(false); } let checkNode = null; let checkNodeArray = target.checkNodeArray; for (let iterator of checkNodeArray) { if (iterator.active && Common5.checkContainsNode(iterator, target)) { checkNode = iterator; break; } } if (checkNode) { target.active = false; checkNode.active = false; target['checkNode'] = checkNode; if (successCallback) { successCallback({ targetNode: target }); } } else { if (failCallback) { failCallback({ targetNode: target }); } } if (target.recoveposi) { target.parent = target.recoveparent; target.setPosition(target.recoveposi); } }; //注册触摸事件 emitTarget['checkNodeArray'] = checkNodeArray; emitTarget['recoveposi'] = emitTarget.getPosition(); emitTarget['recoveparent'] = emitTarget.parent; emitTarget.attr(emitAttr); emitTarget.on(cc.Node.EventType.TOUCH_START, touchStartNode) emitTarget.on(cc.Node.EventType.TOUCH_MOVE, touchMoveNode) emitTarget.on(cc.Node.EventType.TOUCH_CANCEL, touchEndNode) emitTarget.on(cc.Node.EventType.TOUCH_END, touchEndNode) //回调函数集合 let retFuncGroup = { /**设置完成后的事件监听 */ setSuccessListener: (callback: (data_: any) => void) => { successCallback = callback; }, /**设置完成后的事件监听 */ setFailListener: (callback: (data_: any) => void) => { failCallback = callback; }, /**关闭触摸事件 */ closeTouchEvent: () => { emitTarget.off(cc.Node.EventType.TOUCH_START, touchStartNode); emitTarget.off(cc.Node.EventType.TOUCH_MOVE, touchMoveNode); emitTarget.off(cc.Node.EventType.TOUCH_CANCEL, touchEndNode); emitTarget.off(cc.Node.EventType.TOUCH_END, touchEndNode); successCallback = null; failCallback = null; } }; return retFuncGroup; } /** * 节点触摸点击事件注册 * @param emitTarget 触发节点 * @param isEmitTargetHide 触发节点触发后是否隐藏 * @param clickTimes 触发次数 * @param emitAttr 触发节点绑定参数 * @returns 回调函数集合 */ public static onNodeTouchMoreClickEvent( emitTarget: cc.Node, isEmitTargetHide: boolean = true, clickTimes: number = 1, emitAttr: any = {} ) { //触碰回调事件 let completeCallback: (data_: any) => void = null; //当前点击次数 let curClickTimes = 0; //点击判断 let isCanClick = false; //触摸开始 let touchStartNode = (event) => { Common5.playEffect("点击音效"); let target = event.target; console.log('touchStartNode', target.zIndex); if (curClickTimes == 0) { curClickTimes++; setTimeout(() => { curClickTimes = 0; }, 2000); } else { curClickTimes++; } isCanClick = true; setTimeout(() => { isCanClick = false; }, 200); }; //触摸移动 let touchMoveNode = (event) => { }; //触摸结束 let touchEndNode = (event) => { if (!isCanClick && curClickTimes < clickTimes) { return; } let target = event.target; if (isEmitTargetHide) { target.active = false; } if (completeCallback) { completeCallback({ targetNode: target }); } }; //注册触摸事件 emitTarget['recoveposi'] = emitTarget.getPosition(); emitTarget.attr(emitAttr); emitTarget.on(cc.Node.EventType.TOUCH_START, touchStartNode) emitTarget.on(cc.Node.EventType.TOUCH_MOVE, touchMoveNode) //emitTarget.on(cc.Node.EventType.TOUCH_CANCEL, touchEndNode) emitTarget.on(cc.Node.EventType.TOUCH_END, touchEndNode) //回调函数集合 let retFuncGroup = { /**设置完成后的事件监听 */ setCompleteListener: (callback: (data_: any) => void) => { completeCallback = callback; }, /**关闭触摸事件 */ closeTouchEvent: () => { emitTarget.off(cc.Node.EventType.TOUCH_START, touchStartNode); emitTarget.off(cc.Node.EventType.TOUCH_MOVE, touchMoveNode); emitTarget.off(cc.Node.EventType.TOUCH_CANCEL, touchEndNode); emitTarget.off(cc.Node.EventType.TOUCH_END, touchEndNode); completeCallback = null; } }; return retFuncGroup; } /** * 节点触摸点击事件注册 * @param emitTarget 触发节点 * @param isEmitTargetHide 触发节点触发后是否隐藏 * @param longClickTime 长按触发时间 * @param emitAttr 触发节点绑定参数 * @returns 回调函数集合 */ public static onNodeTouchLongClickEvent( emitTarget: cc.Node, isEmitTargetHide: boolean = true, longClickTime: number = 1, emitAttr: any = {} ) { //短按回调事件 let shortClickCallback: (data_: any) => void = null; //长按回调事件 let longClickCallback: (data_: any) => void = null; //点击判断 let isCanClick = false; //触摸开始 let touchStartNode = (event) => { Common5.playEffect("点击音效"); let target = event.target; console.log('touchStartNode', target.zIndex); isCanClick = true; setTimeout(() => { if (isCanClick) { if (isEmitTargetHide) { target.active = false; } if (longClickCallback) { longClickCallback({ targetNode: target }); } isCanClick = false; } }, longClickTime * 1000); }; //触摸移动 let touchMoveNode = (event) => { }; //触摸结束 let touchEndNode = (event) => { if (!isCanClick) { return; } isCanClick = false; let target = event.target; if (isEmitTargetHide) { target.active = false; } if (shortClickCallback) { shortClickCallback({ targetNode: target }); } }; //注册触摸事件 emitTarget['recoveposi'] = emitTarget.getPosition(); emitTarget.attr(emitAttr); emitTarget.on(cc.Node.EventType.TOUCH_START, touchStartNode) emitTarget.on(cc.Node.EventType.TOUCH_MOVE, touchMoveNode) //emitTarget.on(cc.Node.EventType.TOUCH_CANCEL, touchEndNode) emitTarget.on(cc.Node.EventType.TOUCH_END, touchEndNode) //回调函数集合 let retFuncGroup = { /**设置短按的事件监听 */ setShortClickListener: (callback: (data_: any) => void) => { shortClickCallback = callback; }, /**设置长按的事件监听 */ setLongClickListener: (callback: (data_: any) => void) => { longClickCallback = callback; }, /**关闭触摸事件 */ closeTouchEvent: () => { emitTarget.off(cc.Node.EventType.TOUCH_START, touchStartNode); emitTarget.off(cc.Node.EventType.TOUCH_MOVE, touchMoveNode); emitTarget.off(cc.Node.EventType.TOUCH_CANCEL, touchEndNode); emitTarget.off(cc.Node.EventType.TOUCH_END, touchEndNode); shortClickCallback = null; longClickCallback = null; } }; return retFuncGroup; } /** * 节点方向触摸事件注册 * @param emitTarget 触发节点 * @param directIndex 触摸方向 * @param directvalue 移动度数 * @param isEmitTargetHide 触发节点触发后是否隐藏 * @param emitAttr 触发节点绑定参数 * @returns 回调函数集合 */ public static onNodeDirTouchEvent( emitTarget: cc.Node, directIndex: MOVEDIR = MOVEDIR.UP, directvalue: number = 50, isEmitTargetHide: boolean = true, emitAttr: any = {} ) { //触碰回调事件 let completeCallback: (data_: any) => void = null; //触摸开始坐标 let touchStartPosi = null; let callbacks = (target) => { EventMgr.emitEvent_custom(ryw_Event.openBGMove, { open: true }); console.log("++++++++++++++++++++>" + target.name); if (isEmitTargetHide) { target.active = false; } if (completeCallback) { completeCallback({ targetNode: target }); } } //触摸开始 let touchStartNode = (event) => { let target = event.target let posi = event.getLocation()//世界坐标 touchStartPosi = posi console.log('touchStartNode', target.zIndex) EventMgr.emitEvent_custom(ryw_Event.openBGMove, { open: false }); }; //触摸移动 let touchMoveNode = (event) => { let target = event.target let posi = event.getLocation()//世界坐标 if (directIndex == MOVEDIR.UP) { if ((posi.y - touchStartPosi.y) >= directvalue) { console.log('UP') callbacks(target) } } else if (directIndex == MOVEDIR.DOWN) { if ((touchStartPosi.y - posi.y) >= directvalue) { console.log('DOWN') callbacks(target) } } else if (directIndex == MOVEDIR.RIGHT) { if ((posi.x - touchStartPosi.x) >= directvalue) { console.log('RIGHT') callbacks(target) } } else if (directIndex == MOVEDIR.LEFT) { if ((touchStartPosi.x - posi.x) >= directvalue) { console.log('LEFT') callbacks(target) } } }; //触摸结束 let touchEndNode = (event) => { let target = event.target EventMgr.emitEvent_custom(ryw_Event.openBGMove, { open: true }); console.log("++++++++++++++++++++>" + target.name); }; //注册触摸事件 emitTarget['recoveposi'] = emitTarget.getPosition(); emitTarget.attr(emitAttr); emitTarget.on(cc.Node.EventType.TOUCH_START, touchStartNode) emitTarget.on(cc.Node.EventType.TOUCH_MOVE, touchMoveNode) emitTarget.on(cc.Node.EventType.TOUCH_CANCEL, touchEndNode) emitTarget.on(cc.Node.EventType.TOUCH_END, touchEndNode) //回调函数集合 let retFuncGroup = { /**设置完成后的事件监听 */ setCompleteListener: (callback: (data_: any) => void) => { completeCallback = callback; }, /**关闭触摸事件 */ closeTouchEvent: () => { emitTarget.off(cc.Node.EventType.TOUCH_START, touchStartNode); emitTarget.off(cc.Node.EventType.TOUCH_MOVE, touchMoveNode); emitTarget.off(cc.Node.EventType.TOUCH_CANCEL, touchEndNode); emitTarget.off(cc.Node.EventType.TOUCH_END, touchEndNode); completeCallback = null; } }; return retFuncGroup; } /** * 播放spine动画 * @param spineNode 动画节点 * @param spineAnim 动画名 * @param loop 是否循环 * @param isSpineNodeHide 播放完后是否隐藏节点 * @param maskNode 播放动画时拦截输入事件节点 * @returns */ public static playAnimation( spineNode: cc.Node, spineAnim: string, loop: boolean = false, animTime: number = -1, isSpineNodeHide: boolean = false, maskNode: cc.Node = null, ) { //触碰回调事件 let completeCallback: () => void = null; if (maskNode) { maskNode.active = true; } let callbacks = () => { if (isSpineNodeHide) { spineNode.active = false; } if (maskNode) { maskNode.active = false; } if (completeCallback) { completeCallback(); } } spineNode.active = true spineNode.getComponent(sp.Skeleton).setAnimation(0, spineAnim, loop); if (animTime >= 0) { setTimeout(callbacks, animTime * 1000); } else { callbacks(); } //回调函数集合 let retFuncGroup = { /**设置动画播放完后的事件监听 */ setEndListener: (callback: () => void) => { completeCallback = callback; } }; return retFuncGroup; } /** * 播放spine动画 * @param spineNode 动画节点 * @param animName 动画名 * @param loop 是否循环 * @param skinName 皮肤名 * @param completeCallback 触碰回调事件 * @returns */ public static playAnimation2( spineNode: cc.Node, animName: string, loop: boolean = false, skinName: string = null, completeCallback: (spineNode: cc.Node) => void = null ) { spineNode.active = true; if (skinName && skinName != '') { spineNode.getComponent(sp.Skeleton).setSkin(skinName); } if (completeCallback) { spineNode.getComponent(sp.Skeleton).setCompleteListener(() => { completeCallback(spineNode); }); } spineNode.getComponent(sp.Skeleton).setAnimation(0, animName, loop); } /** * 展示提示框 * @param confirmCallback 确认回调 * @param cancelCallback 取消回调 */ public static showAddTimesView( parentNode: cc.Node, confirmCallback?: Function, cancelCallback?: Function, ) { Common.getPrefabFromBundle("WordGame", "gameComPrefab/AddTimesView", parentNode, (node: cc.Node) => { let btnLayout = node.getChildByName("btnLayout"); Common5.btnRegister_custom(btnLayout.getChildByName("加次数"), () => { let tab = { onClose: (finish) => { if (finish) { if (confirmCallback) { confirmCallback(); } node.destroy(); } else { Common5.showTips_custom("广告未观看完!"); } }, onFailed: () => { Common5.showTips_custom("加载广告失败!"); } } AppPlatform.playVideo_custom(tab); }, 1, 0.2, '点击音效'); Common5.btnRegister_custom(btnLayout.getChildByName("取消"), () => { if (cancelCallback) { cancelCallback(); } node.destroy(); }, 1, 0.2, '点击音效'); }) } }