refactor(SS) 重构故事场景,采用继承方式维护场景

This commit is contained in:
chicrobot committed 2026-02-06 20:31:05 +08:00
1 parent d3669bd44e
commit 48960d2a0c
3 files changed
+114 -102

No files matched your search

+24 -6
View File
@@ -11,33 +11,39 @@ export default class WorldTime extends Phaser.Scene {
* @param {string} sceneKey - 场景键名
*/
constructor(sceneKey = 'WorldTime') {
// 场景相关
super(sceneKey)
this.nextScene = 'WorldLand'
// 游戏时间相关
this.gameTime = 0 // 游戏中的时间戳(单位:秒)
// 固定为60秒/分钟,60分钟/小时,24小时/天,30天/月,12月/年
// 固定60秒/分钟,60分钟/小时,24小时/天,30天/月,12月/年
this.minuteSec = 60
this.hourSec = 60 * this.minuteSec
this.daySec = 24 * this.hourSec
this.monthSec = 30 * this.daySec
this.yearSec = 12 * this.monthSec
this.dayStartHour = 6 // 每天开始的小时(24小时制)
this.dayEndHour = 18 // 每天结束的小时(24小时制)
this.gameStartTime = this.toGameTime('1999-12-30 ' + (this.dayStartHour-1).toString().padStart(2, '0') + ':55:00') // 游戏开始时间
this.lastRealTime = 0 // 上一次更新的现实时间戳(毫秒)
this.gameTimeUpdateInterval = 1000/60 // 游戏中的每秒时间更新间隔(毫秒)
this.isDay = true // 昼夜状态
// 层级相关
this.UIDepth = 100 // UI层级深度,确保在其他元素之上
this.maskDepth = 99 // 黑夜遮罩层级,低于UI层级
}
create() {
// 设置场景背景颜色为深灰色
// 设置场景背景颜色
this.cameras.main.setBackgroundColor('#999999')
this.initInput() // 初始化输入事件
// 初始化输入
this.initInput()
this.initDayNight(this.toGameTime('1999-12-30 23:57:00')) // 初始化时间,白天黑夜状态
// 初始化时间
this.initDayNight(this.gameStartTime)
}
/**
* 初始化输入事件
@@ -54,6 +60,18 @@ export default class WorldTime extends Phaser.Scene {
this.scene.start(this.nextScene);
})
}
/**
* 移除输入事件监听器
* 场景切换时调用,避免内存泄漏
*/
removeListener() {
// 移除鼠标点击事件监听器
this.input.off('pointerdown');
// 移除键盘按键事件监听器
this.input.keyboard.off('keydown');
}
/**
* 更新游戏时间
* 每帧调用,刷新游戏时间