DaFuWeng/assets/Script/DialogRoot/SelectNumberNode.ts

117 lines
3.0 KiB
TypeScript
Raw Normal View History

/*
* @Author: WoNiu
* @Date: 2024-03-21 13:28:47
2024-03-25 19:50:16 +08:00
* @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:
*/
2024-03-25 19:50:16 +08:00
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;
2024-03-25 19:50:16 +08:00
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);
2024-03-25 19:50:16 +08:00
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);
2024-03-25 19:50:16 +08:00
twoBba.onMouseLeftDown = () => {
this.onMouseLeftDown(1);
};
this.threeCard = new CardNode();
this.threeCard.setPosition(728, -220);
this.addChild(this.threeCard);
const threeBba = this.threeCard.addComponent(BaseButtonAction);
2024-03-25 19:50:16 +08:00
threeBba.onMouseLeftDown = () => {
this.onMouseLeftDown(2);
};
}
2024-03-25 19:50:16 +08:00
//* 倒计时
initTiming() {
// 倒计时
const time = new TimingProgressBar();
this.addChild(time);
2024-03-25 19:50:16 +08:00
time.tweenerStart(3, () => {
//倒计时缓动完成
//开始翻转动画需要1秒完成动画
this.flipsCard();
2024-03-25 19:50:16 +08:00
//* 2秒后关闭node
setTimeout(() => {
this.doneFunc();
/// 这一帧结束之后调用
director.once(Director.EVENT_END_FRAME, () => {
// 销毁,销毁节点只能在当前帧结束后
this.destroy();
});
}, 2000);
});
}
//* 翻转卡片
2024-03-25 19:50:16 +08:00
flipsCard() {
const cards = [this.oneCard, this.twoCard, this.threeCard];
for (let i = 0; i < cards.length; i++) {
const card = cards[i];
card.Disable = true;
2024-03-25 19:50:16 +08:00
card.flipsAnimation.animationStart(i, "玩家" + i);
}
}
2024-03-25 19:50:16 +08:00
onMouseLeftDown(tag: number) {
const cards = [this.oneCard, this.twoCard, this.threeCard];
cards.forEach((card) => {
card.Disable = true;
});
2024-03-25 19:50:16 +08:00
}
update(deltaTime: number) {}
}