嵌套暂时没法做,先做些常用的单独使用的动作组件
ActionPlace.js (拖到需要做该动作的节点上,不同类型的动作互不影响)
// begin 开始 // reset 重置信息 var ActionDelayTimePlace = cc.Class({ name: "ActionDelayTimePlace", properties: { delayTime: { default: 1, displayName: "延迟时长", min: 0 }, position: { default: cc.v2(), displayName: "位置", }, callback: { default: null, type: cc.Component.EventHandler, displayName: "完成回调", } } }); cc.Class({ extends: cc.Component, properties: { auto: { default: false, displayName: "自动执行", tooltip: "如果false,则需要回调执行该脚本组件的begin方法" }, target: { default: null, type: cc.Node, displayName: "执行的节点", tooltip: "如果没有设置就默认 挂载该脚本的节点" }, times: { default: 1, type: cc.Integer, displayName: "执行次数", tooltip: "一套动作数组 执行的次数", min: 1 }, actionMoves: { default: [], type: ActionDelayTimePlace, displayName: "动作数组", tooltip: "暂时只支持到10个,超过了,自己进来扩写代码" }, allOverCallback: { default: true, displayName: "全部完成/每完成一次回调", tooltip: "勾上:全部完成才回调 不勾:每完成一次都回调,执行几次就调几遍回调" }, overCallbacks: { default: [], type: cc.Component.EventHandler, displayName: "完成回调数组" } }, // LIFE-CYCLE CALLBACKS: // onl oad () {}, start () { this.actionNode = this.target; if (this.actionNode == undefined || this.actionNode == null) { this.actionNode = this.node; } this.actionNode.srcPosition = this.actionNode.position; if (this.auto) { this.begin(); } }, begin () { this.reset(); this.currentTime = this.times; this.action(); }, reset() { this.currentTime = 0; this.actionNode.stopActionByTag(111003); this.actionNode.position = this.actionNode.srcPosition; }, // update (dt) {}, action () { if (this.currentTime > 0) { this.currentTime--; } else { return; } if (this.actionMoves.length == 1) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } else if (this.actionMoves.length == 2) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.delayTime(this.actionMoves[1].delayTime), cc.place(this.actionMoves[1].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[1].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } else if (this.actionMoves.length == 3) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.delayTime(this.actionMoves[1].delayTime), cc.place(this.actionMoves[1].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[1].callback); }.bind(this)), cc.delayTime(this.actionMoves[2].delayTime), cc.place(this.actionMoves[2].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[2].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } else if (this.actionMoves.length == 4) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.delayTime(this.actionMoves[1].delayTime), cc.place(this.actionMoves[1].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[1].callback); }.bind(this)), cc.delayTime(this.actionMoves[2].delayTime), cc.place(this.actionMoves[2].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[2].callback); }.bind(this)), cc.delayTime(this.actionMoves[3].delayTime), cc.place(this.actionMoves[3].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[3].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } else if (this.actionMoves.length == 5) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.delayTime(this.actionMoves[1].delayTime), cc.place(this.actionMoves[1].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[1].callback); }.bind(this)), cc.delayTime(this.actionMoves[2].delayTime), cc.place(this.actionMoves[2].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[2].callback); }.bind(this)), cc.delayTime(this.actionMoves[3].delayTime), cc.place(this.actionMoves[3].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[3].callback); }.bind(this)), cc.delayTime(this.actionMoves[4].delayTime), cc.place(this.actionMoves[4].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[4].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } else if (this.actionMoves.length == 6) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.delayTime(this.actionMoves[1].delayTime), cc.place(this.actionMoves[1].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[1].callback); }.bind(this)), cc.delayTime(this.actionMoves[2].delayTime), cc.place(this.actionMoves[2].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[2].callback); }.bind(this)), cc.delayTime(this.actionMoves[3].delayTime), cc.place(this.actionMoves[3].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[3].callback); }.bind(this)), cc.delayTime(this.actionMoves[4].delayTime), cc.place(this.actionMoves[4].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[4].callback); }.bind(this)), cc.delayTime(this.actionMoves[5].delayTime), cc.place(this.actionMoves[5].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[5].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } else if (this.actionMoves.length == 7) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.delayTime(this.actionMoves[1].delayTime), cc.place(this.actionMoves[1].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[1].callback); }.bind(this)), cc.delayTime(this.actionMoves[2].delayTime), cc.place(this.actionMoves[2].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[2].callback); }.bind(this)), cc.delayTime(this.actionMoves[3].delayTime), cc.place(this.actionMoves[3].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[3].callback); }.bind(this)), cc.delayTime(this.actionMoves[4].delayTime), cc.place(this.actionMoves[4].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[4].callback); }.bind(this)), cc.delayTime(this.actionMoves[5].delayTime), cc.place(this.actionMoves[5].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[5].callback); }.bind(this)), cc.delayTime(this.actionMoves[6].delayTime), cc.place(this.actionMoves[6].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[6].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } else if (this.actionMoves.length == 8) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.delayTime(this.actionMoves[1].delayTime), cc.place(this.actionMoves[1].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[1].callback); }.bind(this)), cc.delayTime(this.actionMoves[2].delayTime), cc.place(this.actionMoves[2].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[2].callback); }.bind(this)), cc.delayTime(this.actionMoves[3].delayTime), cc.place(this.actionMoves[3].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[3].callback); }.bind(this)), cc.delayTime(this.actionMoves[4].delayTime), cc.place(this.actionMoves[4].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[4].callback); }.bind(this)), cc.delayTime(this.actionMoves[5].delayTime), cc.place(this.actionMoves[5].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[5].callback); }.bind(this)), cc.delayTime(this.actionMoves[6].delayTime), cc.place(this.actionMoves[6].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[6].callback); }.bind(this)), cc.delayTime(this.actionMoves[7].delayTime), cc.place(this.actionMoves[7].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[7].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } else if (this.actionMoves.length == 9) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.delayTime(this.actionMoves[1].delayTime), cc.place(this.actionMoves[1].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[1].callback); }.bind(this)), cc.delayTime(this.actionMoves[2].delayTime), cc.place(this.actionMoves[2].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[2].callback); }.bind(this)), cc.delayTime(this.actionMoves[3].delayTime), cc.place(this.actionMoves[3].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[3].callback); }.bind(this)), cc.delayTime(this.actionMoves[4].delayTime), cc.place(this.actionMoves[4].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[4].callback); }.bind(this)), cc.delayTime(this.actionMoves[5].delayTime), cc.place(this.actionMoves[5].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[5].callback); }.bind(this)), cc.delayTime(this.actionMoves[6].delayTime), cc.place(this.actionMoves[6].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[6].callback); }.bind(this)), cc.delayTime(this.actionMoves[7].delayTime), cc.place(this.actionMoves[7].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[7].callback); }.bind(this)), cc.delayTime(this.actionMoves[8].delayTime), cc.place(this.actionMoves[8].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[8].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } else if (this.actionMoves.length == 10) { this.actionNode.runAction(this.actionID = cc.sequence( cc.delayTime(this.actionMoves[0].delayTime), cc.place(this.actionMoves[0].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[0].callback); }.bind(this)), cc.delayTime(this.actionMoves[1].delayTime), cc.place(this.actionMoves[1].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[1].callback); }.bind(this)), cc.delayTime(this.actionMoves[2].delayTime), cc.place(this.actionMoves[2].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[2].callback); }.bind(this)), cc.delayTime(this.actionMoves[3].delayTime), cc.place(this.actionMoves[3].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[3].callback); }.bind(this)), cc.delayTime(this.actionMoves[4].delayTime), cc.place(this.actionMoves[4].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[4].callback); }.bind(this)), cc.delayTime(this.actionMoves[5].delayTime), cc.place(this.actionMoves[5].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[5].callback); }.bind(this)), cc.delayTime(this.actionMoves[6].delayTime), cc.place(this.actionMoves[6].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[6].callback); }.bind(this)), cc.delayTime(this.actionMoves[7].delayTime), cc.place(this.actionMoves[7].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[7].callback); }.bind(this)), cc.delayTime(this.actionMoves[8].delayTime), cc.place(this.actionMoves[8].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[8].callback); }.bind(this)), cc.delayTime(this.actionMoves[9].delayTime), cc.place(this.actionMoves[9].position), cc.callFunc(function() { this.callEventHandler(this.actionMoves[9].callback); }.bind(this)), cc.callFunc(function() { this.action(); this.overCallback(); }.bind(this)))); } this.actionID.setTag(111003); }, overCallback() { if (this.currentTime > 1) { if (this.allOverCallback) { for (let i = 0; i < this.overCallbacks.length; i++) { if (this.overCallbacks[i] != null && this.overCallbacks[i].target != null) { this.overCallbacks[i].emit([this, this.overCallbacks[i].customEventData]); } } } } else { for (let i = 0; i < this.overCallbacks.length; i++) { if (this.overCallbacks[i] != null && this.overCallbacks[i].target != null) { this.overCallbacks[i].emit([this, this.overCallbacks[i].customEventData]); } } } }, callEventHandler(eventHandler) { if (eventHandler && eventHandler.target) { eventHandler.emit([this]); } } });