DaFuWeng/assets/Script/DialogNode/LuckyCoinsNode.ts

136 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: WoNiu
* @Date: 2024-03-26 11:44:58
* @LastEditTime: 2024-03-27 15:49:36
* @LastEditors: WoNiu
* @Description: 幸运硬币效果类型
*/
import {
_decorator,
Sprite,
Director,
director,
Node,
tween,
UITransform,
v2,
Color,
} from "cc";
import { AnimationNode } from "../../GlobalScript/Animation/AnimationNode";
import { BaseSprite } from "../../GlobalScript/CommonComponent/BaseSprite";
import { NpkImage } from "../../Tool/NPKImage";
import { CloseButtonNode } from "../Common/CloseButtonNode";
import { GameRootSingleton } from "../GameRootController";
const { ccclass, property } = _decorator;
/**
* @description: 幸运硬币效果类型
*/
export enum LuckyType {
// 前进三格
GoThree = 0,
// 移动到月光酒馆
YeGuangJiuGuan,
// 移动到决斗场
JueDouChang,
// 移动到海上列车
HaiShangLieChe,
// 我要双倍点数x2
Double,
// 这是我的钱,点数减半
Halve,
// 骑士马战 ,点数+2w
HorseCombat,
// 装备修理, 点数-2w
Servicing,
// 收取费用,夺取其他人 2w 点数
Charge,
}
@ccclass("LuckyCoinsNode")
export class LuckyCoinsNode extends Node {
luckyType: LuckyType;
// 幸运硬币的结果
resultNode: Node;
aniDoneBack: Function;
constructor(type: LuckyType,aniDone:Function) {
super();
this.luckyType = type;
this.aniDoneBack = aniDone;
this.addComponent(UITransform).anchorPoint = v2(0, 1);
this.initResultNode();
this.initLuckyAni();
this.delayShowResult();
}
initActionButton() {
const node = new CloseButtonNode(() => {
this.initLuckyAni();
});
this.addChild(node);
}
initResultNode() {
const node = new Node();
this.addChild(node);
node.setPosition(443, -200);
this.resultNode = node;
node.active = false;
const bs = node.addComponent(BaseSprite);
bs.updateSpriteFrame(NpkImage.luckycoin, this.luckyType);
}
initLuckyAni() {
const lucky = new AnimationNode("ani/luckycoin01.ani", () => {
/// 这一帧结束之后调用
director.once(Director.EVENT_END_FRAME, () => {
// 销毁,销毁节点只能在当前帧结束后
lucky.destroy();
});
});
lucky.setPosition(318.5, -107.5);
this.addChild(lucky);
}
// 延迟显示结果
delayShowResult() {
setTimeout(() => {
this.resultNode.active = true;
setTimeout(() => {
this.resultTweenDestroy();
}, 1000);
}, 1600);
}
// 透明度缓动消失
resultTweenDestroy() {
let obj = { x: 255 };
tween(obj)
.to(0.5, { x: 1 }, { onUpdate: () => {
const spr = this.resultNode.getComponent(Sprite);
spr.color = new Color(255,255,255,obj.x);
}, onComplete: () => {
/// 缓动完成
this.resultNode.active = false;
// 动画完成回调
this.aniDoneBack();
// 销毁节点
director.once(Director.EVENT_END_FRAME, () => {
this.destroy();
});
},easing:'linear'})
.start();
}
}