DaFuWeng/assets/Script/DialogRoot/SelectNumberNode.ts

117 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-21 13:28:47
* @LastEditTime: 2024-03-25 19:44:01
* @LastEditors: WoNiu
* @Description:
*/
/*
* @Author: WoNiu
* @Date: 2024-03-21 13:28:47
* @LastEditTime: 2024-03-22 21:24:13
* @LastEditors: WoNiu
* @Description: 顺序选择卡片节点
*/
import { _decorator, Director, director, Node } from "cc";
import { BaseSprite } from "../../GlobalScript/CommonComponent/BaseSprite";
import { NpkImage } from "../../Tool/NPKImage";
import { BaseButtonAction } from "../../GlobalScript/CommonComponent/BaseButtonAction";
import { CardNode } from "./CardNode";
import { TimingProgressBar } from "../Common/TimingProgressBar";
const { ccclass, property } = _decorator;
/// 选择顺序卡牌Node
@ccclass("SelectNumberNode")
export class SelectNumberNode extends Node {
oneCard: CardNode;
twoCard: CardNode;
threeCard: CardNode;
doneFunc: Function;
constructor() {
super();
this.initBackground();
this.initCards();
this.initTiming();
}
initBackground() {
const node = new Node();
node.setPosition(184.5, -181.5);
const bs = node.addComponent(BaseSprite);
bs.updateSpriteFrame(NpkImage.ingame, 46);
this.addChild(node);
}
initCards() {
this.oneCard = new CardNode();
this.oneCard.setPosition(339, -220);
this.addChild(this.oneCard);
const Onebba = this.oneCard.addComponent(BaseButtonAction);
Onebba.onMouseLeftDown = () => {
this.onMouseLeftDown(0);
};
this.twoCard = new CardNode();
this.twoCard.setPosition(533.5, -220);
this.addChild(this.twoCard);
const twoBba = this.twoCard.addComponent(BaseButtonAction);
twoBba.onMouseLeftDown = () => {
this.onMouseLeftDown(1);
};
this.threeCard = new CardNode();
this.threeCard.setPosition(728, -220);
this.addChild(this.threeCard);
const threeBba = this.threeCard.addComponent(BaseButtonAction);
threeBba.onMouseLeftDown = () => {
this.onMouseLeftDown(2);
};
}
//* 倒计时
initTiming() {
// 倒计时
const time = new TimingProgressBar();
this.addChild(time);
time.tweenerStart(3, () => {
//倒计时缓动完成
//开始翻转动画需要1秒完成动画
this.flipsCard();
//* 2秒后关闭node
setTimeout(() => {
this.doneFunc();
/// 这一帧结束之后调用
director.once(Director.EVENT_END_FRAME, () => {
// 销毁,销毁节点只能在当前帧结束后
this.destroy();
});
}, 2000);
});
}
//* 翻转卡片
flipsCard() {
const cards = [this.oneCard, this.twoCard, this.threeCard];
for (let i = 0; i < cards.length; i++) {
const card = cards[i];
card.Disable = true;
card.flipsAnimation.animationStart(i, "玩家" + i);
}
}
onMouseLeftDown(tag: number) {
const cards = [this.oneCard, this.twoCard, this.threeCard];
cards.forEach((card) => {
card.Disable = true;
});
}
update(deltaTime: number) {}
}