大侠
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.
 
 
 

106 lines
4.8 KiB

//#region 文件引入
import { _decorator, Button, Component, Label, Node, sp, Sprite,Animation, RichText, Prefab, instantiate, tween, Vec3, Vec2, v3, v2, UIOpacity, Color } from "cc";
import UIParse from "../../Mgr_UI/UIParse";
import MathUtils from "../../ExUtils/MathUtils";
import { TRIGGER_TYPE } from "../../const/GameEnum";
//#endregion 文件引入
const {ccclass, property,menu} = _decorator;
@ccclass("Damage_Proxy")
export default class Damage_Proxy extends UIParse{
//#region 节点自动生成
@property(Node)
n_Critical: Node = null;
@property(Label)
lab_text: Label = null;
//#endregion 节点自动生成
private static textPool:Node[]=[];
private yellowcolor:Color = new Color(242,238,52);
private whitecolor:Color = new Color(255,255,255);
private hitcount:number = 0;
static CreateDamageText(_prefab: Prefab) {
if (this.textPool.length) {
return this.textPool.pop();
} else {
return instantiate(_prefab);
}
}
static RecycleDamageText(tNode: Node) {
tNode.removeFromParent();
this.textPool.push(tNode);
}
onAnimationEvent() {
Damage_Proxy.RecycleDamageText(this.node);
}
PlayText(text: string,isCritical:boolean,triggerType:TRIGGER_TYPE) {
// this.hitcount++
// isCritical = isCritical || this.hitcount % 5 == 0;
let offsetX = 0;
if(isCritical){
this.lab_text.fontSize = 55;
}else if(triggerType === TRIGGER_TYPE.SKILL){
this.lab_text.fontSize = 70;
offsetX = -10;
}else{
this.lab_text.fontSize = 50;
}
CNodeUtils.setActive(this.n_Critical,isCritical)
CNodeUtils.setOpacity(this.node, 255);
const tUIOpacity = this.node.getComponent(UIOpacity);
if (isCritical || triggerType === TRIGGER_TYPE.SKILL) {
// 暴击飘字效果:直接向上移动并淡出
const startPos = v3(-120, -10, 0);
const endPos = v3(-120 + offsetX, 20, 0);
this.node.setPosition(startPos);
// this.node.setScale(v3(1.5, 1.5, 1));
const moveUp = tween(this.node).to(0.7, { position: endPos }, { easing: 'quadOut' });
const fadeOut = tween(tUIOpacity).to(0.7, { opacity: 0 });
// const scaleUp = tween(this.node).to(0.7, { scale: v3(1.2, 1.2, 1) });
tween(this.node).parallel(moveUp, fadeOut).call(() => {
// this.node.setScale(v3(1, 1, 1));
this.onAnimationEvent();
}).start();
} else {
// 非暴击飘字效果:保持原来的贝塞尔曲线运动
const Start = v2(MathUtils.randomRangeInt(0, 30), MathUtils.randomRangeInt(0, 30))
const End = v3(170 + MathUtils.randomRangeInt(0, 30), -200, 0);
const Min = v2(End.x * 0.3, 150 + MathUtils.randomRangeInt(0, 50))
const bezier = CNodeUtils.bezierTo(this.node, 1, Start, Min, End, {});
const Opacity = tween(tUIOpacity).delay(0.3).to(0.7, { opacity: 0 });
tween(this.node).parallel(bezier, Opacity).call(() => {
this.onAnimationEvent();
}).start();
}
this.lab_text.color = isCritical ? this.yellowcolor : this.whitecolor;
CNodeUtils.switchText(this.lab_text, text);
}
// PlayText(text: string,isCritical:boolean) {
// if(isCritical){
// this.lab_text.fontSize = 80;
// }
// else{
// this.lab_text.fontSize = 50;
// }
// CNodeUtils.setActive(this.n_Critical,isCritical)
// const Start = v2(MathUtils.randomRangeInt(0, 30), MathUtils.randomRangeInt(0, 30))
// const End = v3(170 + MathUtils.randomRangeInt(0, 30), -200, 0);
// const Min = v2(End.x * 0.3, 150 + MathUtils.randomRangeInt(0, 50))
// CNodeUtils.setOpacity(this.node, 255);
// const tUIOpacity = this.node.getComponent(UIOpacity);
// const bezier = CNodeUtils.bezierTo(this.node, 1, Start, Min, End, {});
// const Opacity = tween(tUIOpacity).delay(0.3).to(0.7, { opacity: 0 });
// tween(this.node).parallel(bezier, Opacity).call(() => {
// this.onAnimationEvent();
// }).start();
// this.lab_text.color = isCritical ? this.yellowcolor : this.whitecolor;
// CNodeUtils.switchText(this.lab_text, text);
// }
}