Commit 92bd04f9 authored by Tt's avatar Tt

处理完成

parent 8b9dd890
......@@ -149,6 +149,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
private activeFireNodes: cc.Node[] = [];
/** 是否正在触摸中 */
private touching: boolean = false;
/** 录音开始的时间(秒) */
private recordStartTime: number = 0;
/** 最大录音时长(秒) */
private maxRecordDuration: number = 30;
/** 用户无操作计时器(秒) */
private inactiveTimer: number = 0;
/** 提示动画显示的时间阈值(秒) */
private hintThreshold: number = 3;
/** 提示动画是否正在播放 */
private isHintAnimPlaying: boolean = false;
/**
* 初始化游戏数据
......@@ -183,6 +193,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
cc.audioEngine.stopAllEffects();
pg.audio.stopAudio(this.audioId);
}
// 隐藏提示手指节点
if (this.btn_finger) {
this.btn_finger.active = false;
}
// 重置提示动画状态
this.isHintAnimPlaying = false;
this.inactiveTimer = 0;
}
/**
* 初始化事件监听
......@@ -242,9 +261,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 设置初始位置
this.node_firetruck.setPosition(cc.v2(initialX, -330));
// 隐藏冲水动画节点
// 隐藏冲水动画节点和提示手指
this.node_firetruck_flush.active = false;
this.btn_finger.active = false;
// 重置提示动画状态和计时器
this.isHintAnimPlaying = false;
this.inactiveTimer = 0;
// 播放龙骨动画
pg.view.playDBAnimation(this.node_firetruck_anim, '移动', -1);
......@@ -259,6 +282,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
.call(() => {
// 播放龙骨动画
pg.view.playDBAnimation(this.node_firetruck_anim, '待机', -1);
// 消防车到达目标位置后立即显示提示手指
this.showHintAnimation();
})
.start();
}
......@@ -346,6 +372,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 如果正在触摸中,不响应新的触摸
if (this.touching) return;
this.touching = true;
// 停止提示动画
this.stopHintAnimation();
// 重置无操作计时器
this.inactiveTimer = 0;
// 随机选择一个火苗节点
const randomIndex = Math.floor(Math.random() * this.activeFireNodes.length);
......@@ -439,11 +471,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
} else {
this.log(`找不到节点: water_${fireIndex}`);
}
// 停止提示动画
this.stopHintAnimation();
pg.view.playDBAnimation(this.node_firetruck_flush, '收水', 1);
this.scheduleOnce(() => {
this.node_firetruck_flush.active = false;
this.touching = false;
// 重置无操作计时器
this.inactiveTimer = 0;
}, 1);
// 检查当前页面是否所有火苗都已处理完毕
......@@ -452,7 +490,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.scheduleOnce(() => {
// 检查是否需要进入下一页
this.nextPage();
}, 1.0); // 延迟2秒,给用户时间看到当前页面的完成状态
}, 1.0); // 延迟1秒,给用户时间看到当前页面的完成状态
}
}
onFireFail() {
......@@ -467,10 +505,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (fireNode) {
fireNode.active = true;
}
// 停止提示动画
this.stopHintAnimation();
pg.view.playDBAnimation(this.node_firetruck_flush, '收水', 1);
this.scheduleOnce(() => {
this.node_firetruck_flush.active = false;
this.touching = false;
// 重置无操作计时器
this.inactiveTimer = 0;
}, 1);
}
nextPage() {
......@@ -767,12 +812,47 @@ export default class SceneComponent extends MyCocosSceneComponent {
/**
* 游戏帧更新函数
* 主要用于更新倒计时显示
* 主要用于更新倒计时显示、自动停止录音和显示提示动画
* @param dt 帧间隔时间(秒)
*/
update(dt) {
// 只在游戏运行状态下更新
if (Game.getIns().state != GAME_STATE.RUNNING) return;
// 处理录音倒计时
if (this.countDown < 999999) {
// 减少倒计时时间
this.countDown -= dt;
// 计算当前录音时长
const currentTime = Date.now() / 1000;
const recordDuration = currentTime - this.recordStartTime;
// 如果倒计时结束或录音时长超过最大值,自动停止录音
if (this.countDown <= 0 || recordDuration >= this.maxRecordDuration) {
// 调用结束录音函数
this.onTouchRecordEnd();
}
}
// 处理提示动画逻辑
if (!this.touching && this.activeFireNodes.length > 0 && this.layout_speak.active === false) {
// 增加无操作计时器
this.inactiveTimer += dt;
// 如果超过阈值且提示动画未播放,显示提示动画
if (this.inactiveTimer >= this.hintThreshold && !this.isHintAnimPlaying) {
this.showHintAnimation();
}
} else {
// 重置无操作计时器
this.inactiveTimer = 0;
// 如果正在播放提示动画且满足停止条件,停止动画
if (this.isHintAnimPlaying && (this.touching || this.activeFireNodes.length === 0 || this.layout_speak.active === true)) {
this.stopHintAnimation();
}
}
}
......@@ -780,6 +860,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
/**
* 开始录音按钮点击处理
* 停止背景音乐,显示倒计时,开始录音
* 录音最长持续30秒,超时自动停止
*/
private onTouchRecord() {
// 停止背景音乐
......@@ -788,12 +869,66 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 使用更新后的showCard方法,传入'recording'状态
this.showCard(true, 'recording');
// 显示倒计时并设置时间
this.countDown = this.startCount;
this.countDown = this.touchData.time || this.startCount; //使用问题指定的时间或默认时间
let requestedTime = this.touchData.time || this.startCount; //使用问题指定的时间或默认时间
// 确保倒计时不超过30秒
this.countDown = Math.min(requestedTime, 30);
// 记录录音开始时间
this.recordStartTime = Date.now() / 1000; // 转换为秒
// 开始录音
courseware && courseware.startTest(this.touchData.txt);
}
/**
* 显示提示动画
* 显示提示手指并执行放大缩小动画
*/
private showHintAnimation() {
// 如果提示动画已经在播放,直接返回
if (this.isHintAnimPlaying) return;
// 标记提示动画正在播放
this.isHintAnimPlaying = true;
// 显示提示手指
this.btn_finger.active = true;
// 设置初始缩放
this.btn_finger.scale = 1.0;
// 创建放大缩小的循环动画
const scaleAction = cc.tween()
.to(0.5, { scale: 1.2 })
.to(0.5, { scale: 1.0 })
.union();
// 重复执行动画
cc.tween(this.btn_finger)
.repeatForever(scaleAction)
.start();
}
/**
* 停止提示动画
* 隐藏提示手指并停止动画
*/
private stopHintAnimation() {
// 如果提示动画没有在播放,直接返回
if (!this.isHintAnimPlaying) return;
// 标记提示动画已停止
this.isHintAnimPlaying = false;
// 停止所有动画
cc.Tween.stopAllByTarget(this.btn_finger);
// 隐藏提示手指
this.btn_finger.active = false;
// 重置缩放
this.btn_finger.scale = 1.0;
}
/**
* 结束录音按钮点击处理
* 停止倒计时,显示播放和重新录制按钮,结束录音
......@@ -804,6 +939,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 隐藏倒计时并设置一个很大的值防止倒计时继续
this.countDown = 999999;
// 重置录音开始时间
this.recordStartTime = 0;
let testData = {
"audioUrl": "https://staging-teach.cdn.ireadabc.com/a8ea7bb153a46941e6f28b7d0dda49f4.mp3",
......
......@@ -184,7 +184,7 @@
(blur)="save()">
</div>
<div class="option-time">
<div class="option-time" style="display:none">
<div class="word-input-title">
<span>录音时间: </span>
</div>
......
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