Commit 42b79416 authored by Tt's avatar Tt

动画增加

parent b659e3a4
...@@ -6903,7 +6903,7 @@ ...@@ -6903,7 +6903,7 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
-3.936, -5,
-353.105, -353.105,
0, 0,
0, 0,
...@@ -7091,7 +7091,7 @@ ...@@ -7091,7 +7091,7 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
-3.936, -6,
-353.105, -353.105,
0, 0,
0, 0,
...@@ -7199,7 +7199,7 @@ ...@@ -7199,7 +7199,7 @@
"__id__": 156 "__id__": 156
} }
], ],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 158 "__id__": 158
......
...@@ -489,6 +489,90 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -489,6 +489,90 @@ export default class SceneComponent extends MyCocosSceneComponent {
* @param hide 是否隐藏卡片,默认为false(显示) * @param hide 是否隐藏卡片,默认为false(显示)
* @param recordState 录音状态,可选值:'init'(初始状态), 'recording'(录制中), 'recorded'(录制完成) * @param recordState 录音状态,可选值:'init'(初始状态), 'recording'(录制中), 'recorded'(录制完成)
*/ */
/**
* 播放录音动画效果
* 循环显示btn_record_0~btn_record_2三个按钮,实现录音中的动画效果
*/
playVoiceAni() {
// 获取录音按钮节点
let btn_record_0 = pg.view.find(this.layout_speak, 'btn_record_0');
let btn_record_1 = pg.view.find(this.layout_speak, 'btn_record_1');
let btn_record_2 = pg.view.find(this.layout_speak, 'btn_record_2');
// 确保所有按钮都存在
if (!btn_record_0 || !btn_record_1 || !btn_record_2) {
return this.log('录音按钮节点不存在');
}
// 初始状态:显示第一个按钮,隐藏其他按钮
btn_record_0.active = true;
btn_record_1.active = false;
btn_record_2.active = false;
// 清除可能存在的旧定时器
if (this._voiceAniTimer) {
clearInterval(this._voiceAniTimer);
this._voiceAniTimer = null;
}
// 当前显示的按钮索引
let currentIndex = 0;
// 创建定时器,每隔200毫秒切换一次按钮显示
this._voiceAniTimer = setInterval(() => {
// 隐藏所有按钮
btn_record_0.active = false;
btn_record_1.active = false;
btn_record_2.active = false;
// 根据当前索引显示对应按钮
switch (currentIndex) {
case 0:
btn_record_0.active = true;
break;
case 1:
btn_record_1.active = true;
break;
case 2:
btn_record_2.active = true;
break;
}
// 更新索引,循环显示三个按钮
currentIndex = (currentIndex + 1) % 3;
}, 200);
}
/**
* 停止录音动画效果
* 停止按钮切换,只显示btn_record_0
*/
stopVoiceAni() {
// 清除定时器
if (this._voiceAniTimer) {
clearInterval(this._voiceAniTimer);
this._voiceAniTimer = null;
}
// 获取录音按钮节点
let btn_record_0 = pg.view.find(this.layout_speak, 'btn_record_0');
let btn_record_1 = pg.view.find(this.layout_speak, 'btn_record_1');
let btn_record_2 = pg.view.find(this.layout_speak, 'btn_record_2');
// 确保所有按钮都存在
if (!btn_record_0 || !btn_record_1 || !btn_record_2) {
return this.log('录音按钮节点不存在');
}
// 只显示第一个按钮,隐藏其他按钮
btn_record_0.active = true;
btn_record_1.active = false;
btn_record_2.active = false;
}
// 录音动画定时器
private _voiceAniTimer: any = null;
showCard(hide: boolean = false, recordState: string = 'init') { showCard(hide: boolean = false, recordState: string = 'init') {
if (!hide) { if (!hide) {
// 显示卡片 // 显示卡片
...@@ -518,28 +602,38 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -518,28 +602,38 @@ export default class SceneComponent extends MyCocosSceneComponent {
btn_stop.active = false; btn_stop.active = false;
btn_start_reset.active = false; btn_start_reset.active = false;
btn_record_replay.active = false; btn_record_replay.active = false;
// 停止录音动画,显示初始状态
this.stopVoiceAni();
break; break;
case 'recording': // 录制中 case 'recording': // 录制中
btn_start.active = false; btn_start.active = false;
btn_stop.active = true; btn_stop.active = true;
btn_start_reset.active = false; btn_start_reset.active = false;
btn_record_replay.active = false; btn_record_replay.active = false;
// 开始播放录音动画
this.playVoiceAni();
break; break;
case 'recorded': // 录制完成 case 'recorded': // 录制完成
btn_start.active = false; btn_start.active = false;
btn_stop.active = false; btn_stop.active = false;
btn_start_reset.active = true; btn_start_reset.active = true;
btn_record_replay.active = true; btn_record_replay.active = true;
// 停止录音动画,显示初始状态
this.stopVoiceAni();
break; break;
default: // 默认显示初始状态 default: // 默认显示初始状态
btn_start.active = true; btn_start.active = true;
btn_stop.active = false; btn_stop.active = false;
btn_start_reset.active = false; btn_start_reset.active = false;
btn_record_replay.active = false; btn_record_replay.active = false;
// 停止录音动画,显示初始状态
this.stopVoiceAni();
} }
} else { } else {
// 隐藏录音界面 // 隐藏录音界面
this.layout_speak.active = false; this.layout_speak.active = false;
// 停止录音动画
this.stopVoiceAni();
} }
} }
......
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