Commit a9cc2e7d authored by Tt's avatar Tt

feat(游戏场景): 添加游戏重启功能及相关UI

parent db60e65e
This diff is collapsed.
...@@ -104,6 +104,12 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -104,6 +104,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.initEvent(); // 初始化事件 this.initEvent(); // 初始化事件
this.initGame(); this.initGame();
} }
restartGame() {
this.initData(); // 初始化数据
this.initView(); // 初始化视图
this.initEvent(); // 初始化事件
this.initGame();
}
/** /**
* 组件销毁时的回调 * 组件销毁时的回调
* 清理事件监听,防止内存泄漏 * 清理事件监听,防止内存泄漏
...@@ -176,6 +182,45 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -176,6 +182,45 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.activeFireNodes = []; this.activeFireNodes = [];
// 初始化触摸状态 // 初始化触摸状态
this.touching = false; this.touching = false;
// 初始化录音相关变量
this.recordStartTime = 0;
this.maxRecordDuration = 30;
// 初始化提示相关变量
this.inactiveTimer = 0;
this.hintThreshold = 3;
this.isHintAnimPlaying = false;
// 初始化音频ID
this.audioId = -1;
// 初始化语音动画定时器
this._voiceAniTimer = null;
// 初始化语音关闭状态
this.onTouchSpeakCloseClosing = false;
// 初始化重试状态
this.tryAgain = false;
this.recordTouching = false;
// 初始化重新开始布局
this.layout_restart = null;
// 重置游戏布局和页面节点到初始状态
if (this.layout_game) {
// 重置游戏布局位置到初始状态(x=0)
this.layout_game.x = 0;
}
// 重置页面节点状态
if (this.page_a) {
this.page_a.active = true;
}
if (this.page_b) {
this.page_b.active = false;
}
} }
/** 音频播放ID */ /** 音频播放ID */
private audioId: any; private audioId: any;
...@@ -202,6 +247,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -202,6 +247,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 重置提示动画状态 // 重置提示动画状态
this.isHintAnimPlaying = false; this.isHintAnimPlaying = false;
this.inactiveTimer = 0; this.inactiveTimer = 0;
const currentPage = 0;
const currentPageNode = currentPage % 2 === 0 ? this.page_a : this.page_b;
const otherPageNode = currentPage % 2 === 0 ? this.page_b : this.page_a;
currentPageNode.x = 0;
otherPageNode.x = 1920;
} }
/** /**
* 初始化事件监听 * 初始化事件监听
...@@ -344,6 +396,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -344,6 +396,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 使用cc.tween实现layout_game向左移动一页的距离(1920) // 使用cc.tween实现layout_game向左移动一页的距离(1920)
cc.tween(this.layout_game) cc.tween(this.layout_game)
.to(3.0, { x: -1920 * currentPage }, { easing: 'cubicOut' }) .to(3.0, { x: -1920 * currentPage }, { easing: 'cubicOut' })
.call(() => {
otherPageNode.x = 1920 * (currentPage + 1);
})
.start(); .start();
cc.tween(this.node_firetruck) cc.tween(this.node_firetruck)
.to(3.0, { x: -400 + 1920 * currentPage }, { easing: 'cubicOut' }) .to(3.0, { x: -400 + 1920 * currentPage }, { easing: 'cubicOut' })
...@@ -521,13 +576,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -521,13 +576,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
nextPage() { nextPage() {
// 切换到下一页 // 切换到下一页
Game.getIns().addPage(); Game.getIns().addPage();
// 判断是否已经是最后一题,如果是则触发游戏结束 // 判断是否已经是最后一题,如果是则触发游戏结束
if (Game.getIns().isOver) { if (Game.getIns().isOver) {
this.gameOver(); this.gameOver();
return; return;
} }
this.showPage(); this.showPage();
} }
...@@ -1229,7 +1284,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1229,7 +1284,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 设置游戏状态为结束 // 设置游戏状态为结束
Game.getIns().state = GAME_STATE.OVER; Game.getIns().state = GAME_STATE.OVER;
showTrebleFirework(cc.find('Canvas/ani'), cc.find('Canvas/RabbonBase').children); showTrebleFirework(cc.find('Canvas/ani'), cc.find('Canvas/RabbonBase').children);
// 准备提交的数据 // 准备提交的数据
let data: any = {}; let data: any = {};
...@@ -1245,6 +1300,21 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1245,6 +1300,21 @@ export default class SceneComponent extends MyCocosSceneComponent {
onHomeworkFinish(data) onHomeworkFinish(data)
// 显示重新开始 // 显示重新开始
this.showRestart();
}
private layout_restart: cc.Node = null;
showRestart() {
if (!this.layout_restart) this.layout_restart = cc.find('Canvas/layout_restart');
this.layout_restart.active = true;
pg.view.touchOn(pg.view.find(this.layout_restart, 'btn_restart'), this.onTouchRestart, this);
}
hideRestart() {
if (!this.layout_restart) this.layout_restart = cc.find('Canvas/layout_restart');
this.layout_restart.active = false;
}
onTouchRestart() {
this.hideRestart();
this.restartGame();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment