192 lines
5.7 KiB
JavaScript
192 lines
5.7 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '225f19nUXJDxorkZOH6rPr7', 'battle_effect_node');
|
|
// Scripts/mod/battle/act/battle_effect_node.js
|
|
|
|
"use strict";
|
|
|
|
var PathTool = require("pathtool");
|
|
var NxSpine = require("nx.fx.spine");
|
|
cc.Class({
|
|
"extends": cc.Component,
|
|
properties: {
|
|
skeleton: {
|
|
"default": null,
|
|
type: sp.Skeleton
|
|
},
|
|
eftSp: {
|
|
"default": null,
|
|
type: NxSpine
|
|
}
|
|
},
|
|
// LIFE-CYCLE CALLBACKS:
|
|
onLoad: function onLoad() {
|
|
this.initConfig();
|
|
},
|
|
initConfig: function initConfig() {
|
|
this.effect_active = true;
|
|
this.action_call_list = {}; // 制动动作回调
|
|
this.model = require("battle_controller").getInstance().getModel();
|
|
},
|
|
start: function start() {},
|
|
/**
|
|
* 创建特效
|
|
* @param {*} parent 特效父节点
|
|
* @param {*} scene_pos 场景位置,像素坐标不是格子
|
|
* @param {*} reverse 是否反转
|
|
* @param {*} res_id 特效id
|
|
*/
|
|
createEffect: function createEffect(parent, scene_pos, reverse, res_id, eftScale) {
|
|
this.parent = parent;
|
|
this.scene_pos = scene_pos;
|
|
this.reverse = reverse || 1;
|
|
this.res_id = res_id;
|
|
if (eftScale) {
|
|
this.skeleton_time_scale = eftScale;
|
|
}
|
|
this.createEffectWnd();
|
|
},
|
|
// 创建特效具体
|
|
createEffectWnd: function createEffectWnd() {
|
|
this.node.scaleX = this.reverse;
|
|
this.node.angle = 0;
|
|
this.node.opacity = 255;
|
|
if (this.parent) {
|
|
this.parent.addChild(this.node);
|
|
}
|
|
|
|
// 设置位置
|
|
this.node.setPosition(this.scene_pos.x, this.scene_pos.y);
|
|
// 设置当前的模型速率
|
|
// if (this.skeleton_time_scale) {
|
|
// this.skeleton.timeScale = this.skeleton_time_scale;
|
|
// this.skeleton_time_scale = null;
|
|
// } else {
|
|
var timeScale = this.model.getTimeScale();
|
|
// this.skeleton.timeScale = timeScale;
|
|
this.skeleton_time_scale = timeScale;
|
|
// }
|
|
this.resetInitStatus();
|
|
this.registerEvent();
|
|
},
|
|
// 设置特效位置
|
|
resetScenePos: function resetScenePos(scene_pos) {
|
|
this.scene_pos = scene_pos;
|
|
if (this.node) {
|
|
this.node.setPosition(this.scene_pos.x, this.scene_pos.y);
|
|
}
|
|
},
|
|
// 特效反转
|
|
resetReverse: function resetReverse(reverse) {
|
|
this.reverse = reverse;
|
|
if (this.node) {
|
|
this.node.scaleX = this.reverse;
|
|
}
|
|
},
|
|
// 添加对象
|
|
registerEvent: function registerEvent() {
|
|
this.skeleton.setCompleteListener(function (trackEntry, loopCount) {
|
|
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
|
|
if (this.over_func) {
|
|
this.over_func(animationName);
|
|
// 清掉动作事件
|
|
this.over_func = null;
|
|
this.event_func = null;
|
|
// 单循环特效,可以直接清掉,这里可能会有问题,暂时这样处理
|
|
this.play_action_name = "";
|
|
}
|
|
}.bind(this));
|
|
this.skeleton.setEventListener(function (trackEntry, event) {
|
|
if (this.event_func) {
|
|
this.event_func(event.data.name);
|
|
}
|
|
}.bind(this));
|
|
},
|
|
// 设置动作伴随事件和动作结束事件回调
|
|
setAnimationActionFunc: function setAnimationActionFunc(event_func, over_func) {
|
|
this.event_func = event_func;
|
|
this.over_func = over_func;
|
|
},
|
|
// 播放动作
|
|
playActionOnce: function playActionOnce(action_name, res_name, is_loop) {
|
|
var _this = this;
|
|
res_name = res_name || "action";
|
|
if (is_loop == null) {
|
|
is_loop = true;
|
|
}
|
|
this.effect_play_key = Utils.getNorKey(this.res_id, action_name); //储存一下当前特效资源和动作
|
|
this.node.name = this.effect_play_key;
|
|
var skeleton_path = PathTool.getSpinePath(this.res_id, res_name, false);
|
|
this.skeleton.skeletonData = null;
|
|
if (this.play_action_res == this.res_id) {
|
|
this.eftSp.load(skeleton_path, function (_e) {
|
|
if (!_e) {
|
|
_this.eftSp.action(action_name, is_loop, null, _this.skeleton_time_scale);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
this.eftSp.load(skeleton_path, function (_e) {
|
|
if (!_e) {
|
|
_this.eftSp.action(action_name, is_loop, null, _this.skeleton_time_scale);
|
|
_this.play_action_res = _this.res_id;
|
|
}
|
|
});
|
|
},
|
|
getEffectKey: function getEffectKey() {
|
|
return this.effect_play_key || "";
|
|
},
|
|
// 当前深度值
|
|
setLocalZOrder: function setLocalZOrder(zIndex) {
|
|
if (this.node) {
|
|
this.node.zIndex = zIndex;
|
|
}
|
|
},
|
|
// 挂接到战斗单位身上的特效,当引用次数为0的时候,不需要移除掉,只要不可见,退出单位统一移除
|
|
setActiveEffect: function setActiveEffect(status) {
|
|
this.effect_active = status;
|
|
if (this.node) {
|
|
// this.node.active = status;
|
|
this.node.opacity = status ? 255 : 0;
|
|
if (!status) {
|
|
this.resetInitStatus();
|
|
}
|
|
}
|
|
},
|
|
// 初始化状态
|
|
resetInitStatus: function resetInitStatus() {
|
|
if (this.skeleton) {
|
|
this.skeleton.setToSetupPose();
|
|
this.skeleton.clearTracks();
|
|
}
|
|
},
|
|
// 子弹需要旋转角度
|
|
setRotation: function setRotation(degree) {
|
|
if (this.node) {
|
|
this.node.angle = degree;
|
|
}
|
|
},
|
|
// 设置特效的播放速率
|
|
setTimeScale: function setTimeScale(speed) {
|
|
// this.skeleton_time_scale = speed;
|
|
// this.eftSp.setTimeScale(speed);
|
|
if (this.skeleton == null || this.skeleton.skeletonData == null) {
|
|
this.skeleton_time_scale = speed;
|
|
} else {
|
|
if (this.skeleton_timeScale == speed) return;
|
|
this.skeleton_timeScale = speed;
|
|
this.skeleton.timeScale = speed;
|
|
}
|
|
},
|
|
// 战斗动作播报
|
|
runAction: function runAction(action) {
|
|
if (this.node) {
|
|
this.node.stopAllActions();
|
|
this.node.runAction(action);
|
|
}
|
|
},
|
|
onDestroy: function onDestroy() {
|
|
this.initConfig();
|
|
} // update (dt) {},
|
|
});
|
|
|
|
cc._RF.pop(); |