277 lines
10 KiB
JavaScript
277 lines
10 KiB
JavaScript
import GameModel from "../ts/core/GameModel";
|
|
import WingUtil from "../ts/wing/WingUtil";
|
|
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
|
|
import WeaponUtil from "../ts/weapon/WeaponUtil";
|
|
import ShapeUtil from "../ts/shape/ShapeUtil";
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
properties: {
|
|
animationNode: cc.Node,
|
|
maskNode: cc.Node,
|
|
wingleft: cc.Node,
|
|
wingright: cc.Node,
|
|
weaponNode: cc.Node,
|
|
weaponNode1: cc.Node,
|
|
RoleshadowNode: cc.Node,
|
|
effNode: cc.Node,
|
|
footPNode: cc.Node,
|
|
footEffPre: cc.Prefab
|
|
},
|
|
|
|
onLoad() {
|
|
this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this));
|
|
},
|
|
offTouchRole() {
|
|
this.node.off(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this));
|
|
},
|
|
setInfo(objinfo) {
|
|
this.resid = objinfo.resid;
|
|
this.weapon = objinfo.weapon;
|
|
let temp = GameModel.conf_res_anchor[this.resid];
|
|
let anchorY = temp.anchorY;
|
|
let anchorX = temp.anchorX;
|
|
this.animationNode.anchorY = anchorY;
|
|
this.animationNode.anchorX = anchorX;
|
|
this.maskNode.anchorY = anchorY;
|
|
this.maskNode.anchorX = anchorX;
|
|
// this.effNode.anchorY = this.animationNode.anchorY;
|
|
// this.effNode.anchorX = this.animationNode.anchorX;
|
|
this.RoleshadowNode.anchorY = anchorY;
|
|
this.RoleshadowNode.anchorX = anchorX;
|
|
this.RoleshadowNode.scaleX = 450 / this.RoleshadowNode.width;
|
|
this.RoleshadowNode.scaleY = 450 / this.RoleshadowNode.height;
|
|
this.weaponNode.anchorY = anchorY;
|
|
this.weaponNode.anchorX = anchorX;
|
|
if(this.resid == 3005){
|
|
//this.effNode.setPosition(cc.v2(0, -125));
|
|
this.animationNode.scaleX = 0.8;
|
|
this.animationNode.scaleY = 0.8;
|
|
this.RoleshadowNode.scaleX = this.RoleshadowNode.scaleX*0.8;
|
|
this.RoleshadowNode.scaleY = this.RoleshadowNode.scaleY*0.8;
|
|
}
|
|
if (this.maskNode && (objinfo.color1 != 0 || objinfo.color2 != 0)) {
|
|
this.showColorMask1(this.hxcolorTransfrom(objinfo.color1), this.hxcolorTransfrom(objinfo.color2))
|
|
}
|
|
this.playAnimation('stand');
|
|
ShapeUtil.playshadowAni(this.RoleshadowNode, this.resid, 1, 'stand', this);
|
|
//this.addWeaponAnimation('stand', 1);
|
|
WeaponUtil.addWeaponAnimation(this.weapon, this.weaponNode, this.animationNode, this, this.resid, 'stand', 1, 2);
|
|
|
|
if (objinfo.wingId)
|
|
WingUtil.playAni(this.node, this.resid, 1, "stand", 0, objinfo.wingId);
|
|
},
|
|
changeFootEff(id) {
|
|
this.unscheduleAllCallbacks();
|
|
this.addFootEffFunc = function () {
|
|
let goItem = cc.instantiate(this.footEffPre);
|
|
goItem.parent = this.footPNode;
|
|
goItem.name = "footEff";
|
|
goItem.setPosition(cc.v2(0, -35));
|
|
goItem.getComponent('footEff').init2(id, 1, 1);
|
|
}
|
|
this.addFootEffFunc()
|
|
this.schedule(this.addFootEffFunc, 0.5, cc.macro.REPEAT_FOREVER, 0);
|
|
},
|
|
stopFootEff() {
|
|
this.unschedule(this.addFootEffFunc);
|
|
},
|
|
stopBodyEff() {
|
|
this.effNode.active = false;
|
|
},
|
|
changeBodyEff(id) {
|
|
this.effNode.active = false;
|
|
let clips = this.effNode.getComponent(cc.Animation).getClips();
|
|
for (const clip of clips) {
|
|
this.effNode.getComponent(cc.Animation).stop(clip.name);
|
|
this.effNode.getComponent(cc.Animation).removeClip(clip, true);
|
|
}
|
|
this.playBodyEff(id);
|
|
},
|
|
playBodyEff(id) {
|
|
if (id == 0) {
|
|
this.effNode.active = false;
|
|
return
|
|
}
|
|
var name = `${id}`;
|
|
|
|
let anim = this.effNode.getComponent(cc.Animation);
|
|
if (!anim) {
|
|
return;
|
|
}
|
|
let clips = anim.getClips();
|
|
for (let clip of clips) {
|
|
if (clip.name == name) {
|
|
this.effNode.active = true;
|
|
this.effNode.getComponent(cc.Animation).play(name);
|
|
return;
|
|
}
|
|
}
|
|
this.effNode.active = false;
|
|
let self = this;
|
|
let url = `body_eff/${name}`;
|
|
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
|
|
if (error) {
|
|
cc.warn(`$警告:加載角色動畫資源失敗${url}`);
|
|
return;
|
|
}
|
|
let curFrames = atlas.getSpriteFrames();
|
|
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 10);
|
|
curClip.name = name;
|
|
curClip.wrapMode = cc.WrapMode.Loop;
|
|
let nodeAni = self.effNode.getComponent(cc.Animation);
|
|
if (nodeAni) {
|
|
nodeAni.addClip(curClip);
|
|
nodeAni.play(name);
|
|
}
|
|
self.effNode.active = true;
|
|
});
|
|
},
|
|
/*
|
|
* 顏色轉換
|
|
*/
|
|
hxcolorTransfrom(color) {
|
|
let num = color;
|
|
let r = Math.floor(num / 256 / 256);
|
|
let g = Math.floor(num / 256 % 256);
|
|
let b = Math.floor(num % 256);
|
|
return new cc.Color(r, g, b);
|
|
},
|
|
showColorMask1(color1, color2) {
|
|
if (!color1 || !color2) return
|
|
if (!this.maskNode) return
|
|
if (color1.r == 0 && color1.g == 0 && color1.b == 0 && color2.r == 0 && color2.g == 0 && color2.b == 0) {
|
|
this.maskNode.active = false;
|
|
} else {
|
|
this.maskNode.active = true;
|
|
}
|
|
|
|
let logic = this.maskNode.getComponent('role_color');
|
|
if (!logic) return;
|
|
if (color1.r != 0 || color1.g != 0 || color1.b != 0) {
|
|
let t = Math.floor(color1.r) * 1000000 + Math.floor(color1.g) * 1000 + Math.floor(color1.b);
|
|
logic.dH1 = t;
|
|
} else {
|
|
logic.dH1 = 0;
|
|
}
|
|
|
|
if (color2.r != 0 || color2.g != 0 || color2.b != 0) {
|
|
let t = Math.floor(color2.r) * 1000000 + Math.floor(color2.g) * 1000 + Math.floor(color2.b);
|
|
logic.dH2 = t;
|
|
} else {
|
|
logic.dH2 = 0;
|
|
}
|
|
|
|
},
|
|
playAnimation(name) {
|
|
if (this.animationEFNode)
|
|
this.animationEFNode.active = false;
|
|
let self = this;
|
|
let url = `shap/${this.resid}/${name}_1`;
|
|
let url2 = `shape_mask/${this.resid}/${name}_1`;
|
|
cc.loader.loadRes(url, cc.SpriteAtlas, function (error, atlas) {
|
|
if (error) {
|
|
cc.warn(`$警告:加載資源${url}失敗!`);
|
|
return;
|
|
}
|
|
|
|
let curFrames = [];
|
|
for (let i = 1; ; i++) {
|
|
let frame = atlas.getSpriteFrame(i);
|
|
if (frame) curFrames.push(frame);
|
|
else break;
|
|
}
|
|
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 15);
|
|
curClip.name = name;
|
|
curClip.wrapMode = cc.WrapMode.Loop;
|
|
if (!self.animationNode) {
|
|
console.warn("未找到動畫節點")
|
|
return
|
|
}
|
|
let nodeAni = self.animationNode.getComponent(cc.Animation);
|
|
nodeAni.addClip(curClip);
|
|
nodeAni.play(name);
|
|
|
|
self.scheduleOnce(() => {
|
|
self.animationNode.scaleX = 500 / self.animationNode.width;
|
|
self.animationNode.scaleY = 500 / self.animationNode.height;
|
|
self.animationNode.opacity = 255;
|
|
if (!self.maskNode) return
|
|
}, 0);
|
|
});
|
|
|
|
cc.loader.loadRes(url2, cc.SpriteAtlas, function (error, atlas) {
|
|
if (error) {
|
|
return;
|
|
}
|
|
let curFrames = [];
|
|
for (let i = 1; ; i++) {
|
|
let frame = atlas.getSpriteFrame(i);
|
|
if (frame) curFrames.push(frame);
|
|
else break;
|
|
}
|
|
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 15);
|
|
curClip.name = name;
|
|
curClip.wrapMode = cc.WrapMode.Loop;
|
|
|
|
let nodeAni = self.maskNode.getComponent(cc.Animation);
|
|
nodeAni.addClip(curClip);
|
|
nodeAni.play(name);
|
|
|
|
});
|
|
},
|
|
|
|
clear() {
|
|
let weaponNode = this.weaponNode;
|
|
if (weaponNode) {
|
|
let clips = weaponNode.getComponent(cc.Animation).getClips();
|
|
for (const clip of clips) {
|
|
weaponNode.getComponent(cc.Animation).stop(clip.name);
|
|
weaponNode.getComponent(cc.Animation).removeClip(clip, true);
|
|
}
|
|
}
|
|
let weaponNode1 = this.weaponNode1;
|
|
if (weaponNode1) {
|
|
let clips = weaponNode1.getComponent(cc.Animation).getClips();
|
|
for (const clip of clips) {
|
|
weaponNode1.getComponent(cc.Animation).stop(clip.name);
|
|
weaponNode1.getComponent(cc.Animation).removeClip(clip, true);
|
|
}
|
|
}
|
|
let animationNode = this.animationNode;
|
|
if (animationNode) {
|
|
let clips = animationNode.getComponent(cc.Animation).getClips();
|
|
for (const clip of clips) {
|
|
animationNode.getComponent(cc.Animation).stop(clip.name);
|
|
animationNode.getComponent(cc.Animation).removeClip(clip, true);
|
|
}
|
|
}
|
|
let maskNode = this.maskNode;
|
|
if (maskNode) {
|
|
let clips = maskNode.getComponent(cc.Animation).getClips();
|
|
for (const clip of clips) {
|
|
maskNode.getComponent(cc.Animation).stop(clip.name);
|
|
maskNode.getComponent(cc.Animation).removeClip(clip, true);
|
|
}
|
|
}
|
|
},
|
|
|
|
touchBegan(event) {
|
|
event.stopPropagation();
|
|
this.playAnimation('stand');
|
|
//this.addWeaponAnimation('run', 1);
|
|
ShapeUtil.playshadowAni(this.RoleshadowNode, this.resid, 1, 'stand', this);
|
|
WeaponUtil.addWeaponAnimation(this.weapon, this.weaponNode, this.animationNode, this, this.resid, 'stand', 1, 2);
|
|
this.node.stopAllActions();
|
|
this.node.runAction(cc.sequence(cc.delayTime(10), cc.callFunc(() => {
|
|
this.playAnimation('stand');
|
|
//this.addWeaponAnimation('stand', 1);
|
|
ShapeUtil.playshadowAni(this.RoleshadowNode, this.resid, 1, 'stand', this);
|
|
WeaponUtil.addWeaponAnimation(this.weapon, this.weaponNode, this.animationNode, this, this.resid, 'stand', 1, 2);
|
|
})));
|
|
},
|
|
|
|
onClose() {
|
|
this.unscheduleAllCallbacks();
|
|
}
|
|
});
|