Files
dino/assets/seripts/ui/PauseModal.ts
2026-05-12 06:46:31 +08:00

57 lines
1.3 KiB
TypeScript

import { _decorator, Component, director, Node } from "cc";
import { EventDispatcher } from "../libs/EventDispatcher";
import Common from "../libs/Common";
const { ccclass, property } = _decorator;
@ccclass("PauseModal")
export class PauseModal extends Component {
start() {
// 隐藏暂停游戏弹窗
this.node.active = false;
// 初始化位置
this.node.setPosition(0, 0, 0);
// 监听继续游戏事件
EventDispatcher.getTarget().on(
EventDispatcher.SHOW_PAUSE_MODAL,
this.showModal,
this,
);
}
// 显示弹窗
showModal() {
this.node.active = true;
// 设置暂停游戏背景色
Common.setPageBackgroundColorAsDino(this.node);
// 暂停游戏
director.pause();
// 发送暂停游戏事件
EventDispatcher.getTarget().emit(EventDispatcher.GAME_PAUSE);
// 发送继续游戏弹窗
EventDispatcher.getTarget().emit(EventDispatcher.SHOW_CONTINUE_MODAL);
}
// 关闭弹窗
closeModal() {
this.node.active = false;
// 恢复游戏继续
director.resume();
}
// 回到首页
backToHome() {
// 恢复游戏继续
director.resume();
// 跳转到首页
director.loadScene("home");
}
// 继续游戏
resumeGame() {
// 关闭弹窗
this.closeModal();
}
update(deltaTime: number) {}
}