Commit 81f5dddc authored by Tt's avatar Tt

基础流程完成

parent 83628316
This diff is collapsed.
...@@ -25,15 +25,16 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -25,15 +25,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
@property(dg_xiaodi) xiaodi: dg_xiaodi = null;
async onLoadEnd() { async onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考 // TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData(); this.initData();
this.initView(); this.initView();
this.initEvent(); this.initEvent();
// pg.view.find(this, 'layout_xiaodi').getComponent(dg_xiaodi).playEnter(this.data.npcAudio).then(() => { this.xiaodi.playEnter(this.data.npcAudio).then(() => {
// this.initGame();
// })
this.initGame(); this.initGame();
})
// this.initGame();
} }
_cantouch = null; _cantouch = null;
...@@ -63,6 +64,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -63,6 +64,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Node) label_tip_wait: cc.Node = null; @property(cc.Node) label_tip_wait: cc.Node = null;
@property(cc.Node) label_tip_ing: cc.Node = null; @property(cc.Node) label_tip_ing: cc.Node = null;
@property(cc.Node) rich_content: cc.Node = null; @property(cc.Node) rich_content: cc.Node = null;
@property(cc.Node) btn_go: cc.Node = null;
// 初始化页面 // 初始化页面
initView() { initView() {
...@@ -74,17 +76,16 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -74,17 +76,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
// 事件监听 // 事件监听
initEvent() { initEvent() {
pg.view.touchOn(this.btn_go, this.onTouchNext, this);
pg.view.touchOn(this.btn_restart, this.onTouchRestart, this);
pg.view.touchOn(this.btn_vioce, this.onTouchRecord, this); pg.view.touchOn(this.btn_vioce, this.onTouchRecord, this);
pg.view.touchOn(pg.view.find(this.btn_vioce,'img_ing'), this.onTouchRecordEnd, this); pg.view.touchOn(pg.view.find(this.btn_vioce, 'img_ing'), this.onTouchRecordEnd, this);
} }
// 初始化游戏 // 初始化游戏
initGame() { initGame() {
this.nextStage(); this.nextStage();
} }
//1. 完成录音倒计时等部分代码。
//2. 完成录音结果匹配代码(dg17)
//3. 增加录音结果音频等
//4. 右下角角色的音频播放动作 //4. 右下角角色的音频播放动作
//5. 视频播放 //5. 视频播放
...@@ -107,6 +108,20 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -107,6 +108,20 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.btn_vioce.active = true; this.btn_vioce.active = true;
pg.view.visible(pg.view.find(this.btn_vioce, 'img_ing'), false) pg.view.visible(pg.view.find(this.btn_vioce, 'img_ing'), false)
this.label_tip_wait.active = true; this.label_tip_wait.active = true;
// 展示下一题
this.btn_go.active = true;
if (!this.nextQuestion) {
pg.view.setString(pg.view.find(this.btn_go, 'text'), '看影像')
} else {
pg.view.setString(pg.view.find(this.btn_go, 'text'), '下一题')
}
this._cantouch = false;
this.xiaodi.playQuestionVoice(this.currentQuestion.startAudio).then(() => {
this._cantouch = true;
})
} }
//按钮触发,使用的方法 //按钮触发,使用的方法
...@@ -146,6 +161,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -146,6 +161,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.visible(pg.view.find(this.btn_vioce, 'img_ing'), false) pg.view.visible(pg.view.find(this.btn_vioce, 'img_ing'), false)
} }
async onTouchRecord() { async onTouchRecord() {
if (!this._cantouch) return;
if (this.recording) return; if (this.recording) return;
if (this.recordAudio) return; if (this.recordAudio) return;
this.recording = true; this.recording = true;
...@@ -201,7 +217,55 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -201,7 +217,55 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.rich_content.active = true; this.rich_content.active = true;
const richText = this.rich_content.getComponent(cc.RichText); const richText = this.rich_content.getComponent(cc.RichText);
richText.string = str; richText.string = str;
// 处理正确错误
this.scheduleOnce(() => {
if (isRight) {
this.xiaodi.playQuestionVoice(this.currentQuestion.rightAudio).then(() => {
this._cantouch = true;
this.showNextBtn();
})
} else {
this.xiaodi.playQuestionVoice(this.currentQuestion.errorAudio).then(() => {
this._cantouch = true;
})
} }
}, 0.5)
}
showNextBtn() {
}
showVideo() {
return new Promise(reslove => {
reslove('')
})
}
onTouchRestart() {
// 处理展示视频内容
this.showVideo().then(() => {
// 底部显示为重新查看
this.btn_restart.active = true;
// 播放小迪结束的动作与gameOver相关内容
this.gameOver();
})
}
onTouchNext() {
if (this.recording) return;
if (!this.nextQuestion) {
// 处理展示视频内容
this.showVideo().then(() => {
// 底部显示为重新查看
this.btn_restart.active = true;
// 播放小迪结束的动作与gameOver相关内容
this.gameOver();
})
} else {
this.xiaodi.playQuestionVoiceEnd();
this.nextStage();
}
}
showData(data) { showData(data) {
let list = data.result.sentences[0].details; let list = data.result.sentences[0].details;
// 列表处理 // 列表处理
...@@ -253,6 +317,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -253,6 +317,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.find(this, 'layout_xiaodi').getComponent(dg_xiaodi).playOverEnd() pg.view.find(this, 'layout_xiaodi').getComponent(dg_xiaodi).playOverEnd()
} }
private gameOver() { private gameOver() {
// 按钮显示未下一题的显示内容
this.showXiaodi(); this.showXiaodi();
} }
onTouchExit() { onTouchExit() {
......
...@@ -7,50 +7,29 @@ export default class dg_xiaodi extends cc.Component { ...@@ -7,50 +7,29 @@ export default class dg_xiaodi extends cc.Component {
@property(cc.Node) @property(cc.Node)
aniRole: cc.Node = null; aniRole: cc.Node = null;
@property moveX: number = 500;
private defaultX: number;
onLoad() { onLoad() {
this.defaultX = this.aniRole.x;
} }
private audioIdEnter: any; private audioIdEnter: any;
playEnter(audioUrl) { playEnter(audioUrl) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.node.active = true; this.node.active = true;
let startX = this.defaultX + this.moveX; let startX = 1500
this.aniRole.x = startX; this.aniRole.x = startX;
cc.tween(this.aniRole) cc.tween(this.aniRole)
.call(() => { .call(() => {
pg.view.playDBAnimation(this.aniRole, 'run'); pg.view.playDBAnimation(this.aniRole, 'run');
if (this.moveX < 0) {
this.aniRole.scaleX = -this.aniRole.scaleX;
}
}) })
.to(0.5, { x: 0 }) .to(0.5, { x: 800 })
.call(() => { .call(() => {
if (this.moveX < 0) {
this.aniRole.scaleX = -this.aniRole.scaleX;
}
pg.view.playDBAnimation(this.aniRole, 'talk'); pg.view.playDBAnimation(this.aniRole, 'talk');
pg.audio.playAudioByUrl(audioUrl, () => { pg.audio.playAudioByUrl(audioUrl, () => {
this.audioIdEnter = null; this.audioIdEnter = null;
cc.tween(this.aniRole)
.call(() => {
pg.view.playDBAnimation(this.aniRole, 'run');
if (this.moveX < 0) {
this.aniRole.scaleX = -this.aniRole.scaleX;
}
})
.to(0.5, { x: -1800 })
.call(() => {
this.scheduleOnce(() => { this.scheduleOnce(() => {
this.playEnterEnd() this.playEnterEnd()
resolve(''); resolve('');
}, 0.5) }, 0.5)
})
.start();
}, audioId => { }, audioId => {
this.audioIdEnter = audioId; this.audioIdEnter = audioId;
}) })
...@@ -59,38 +38,88 @@ export default class dg_xiaodi extends cc.Component { ...@@ -59,38 +38,88 @@ export default class dg_xiaodi extends cc.Component {
}); });
} }
playEnterEnd() { playEnterEnd() {
this.node.active = false; // this.node.active = false;
pg.view.playDBAnimation(this.aniRole, 'normal');
if (this.audioIdEnter) { if (this.audioIdEnter) {
cc.audioEngine.stopEffect(this.audioIdEnter) cc.audioEngine.stopEffect(this.audioIdEnter)
} }
} }
private audioIdOver: any;
playOver(audioUrl) { // private audioIdStart: any;
this.node.active = true; // playQuestionStart(audioUrl) {
let startX = this.defaultX + this.moveX; // return new Promise((resolve, reject) => {
this.aniRole.x = startX; // pg.view.playDBAnimation(this.aniRole, 'talk');
cc.tween(this.aniRole)
.call(() => { // pg.audio.playAudioByUrl(audioUrl, () => {
pg.view.playDBAnimation(this.aniRole, 'run'); // this.audioIdStart = null;
if (this.moveX < 0) { // this.scheduleOnce(() => {
this.aniRole.scaleX = -this.aniRole.scaleX; // this.playQuestionStartEnd()
} // resolve('');
}) // }, 0.5)
.to(0.3, { x: this.defaultX }) // }, audioId => {
.call(() => { // this.audioIdStart = audioId;
if (this.moveX < 0) { // })
this.aniRole.scaleX = -this.aniRole.scaleX; // })
} // }
// playQuestionStartEnd() {
// pg.view.playDBAnimation(this.aniRole, 'normal');
// if (this.audioIdStart) {
// cc.audioEngine.stopEffect(this.audioIdStart)
// }
// }
private audioIdVoice: any;
playQuestionVoice(audioUrl) {
return new Promise((resolve, reject) => {
pg.view.playDBAnimation(this.aniRole, 'talk'); pg.view.playDBAnimation(this.aniRole, 'talk');
pg.audio.playAudioByUrl(audioUrl, () => { pg.audio.playAudioByUrl(audioUrl, () => {
this.audioIdOver = null; this.audioIdVoice = null;
pg.view.playDBAnimation(this.aniRole, 'normal'); this.scheduleOnce(() => {
this.playQuestionVoiceEnd()
resolve('');
}, 0.5)
}, audioId => { }, audioId => {
this.audioIdOver = audioId; this.audioIdVoice = audioId;
}) })
}) })
.start(); }
playQuestionVoiceEnd() {
pg.view.playDBAnimation(this.aniRole, 'normal');
if (this.audioIdVoice) {
cc.audioEngine.stopEffect(this.audioIdVoice)
}
}
private audioIdOver: any;
playOver(audioUrl) {
this.node.active = true;
// let startX = this.defaultX + this.moveX;
// this.aniRole.x = startX;
// cc.tween(this.aniRole)
// .call(() => {
// pg.view.playDBAnimation(this.aniRole, 'run');
// if (this.moveX < 0) {
// this.aniRole.scaleX = -this.aniRole.scaleX;
// }
// })
// .to(0.3, { x: this.defaultX })
// .call(() => {
// if (this.moveX < 0) {
// this.aniRole.scaleX = -this.aniRole.scaleX;
// }
// pg.view.playDBAnimation(this.aniRole, 'talk');
// pg.audio.playAudioByUrl(audioUrl, () => {
// this.audioIdOver = null;
// pg.view.playDBAnimation(this.aniRole, 'normal');
// }, audioId => {
// this.audioIdOver = audioId;
// })
// })
// .start();
} }
playOverEnd() { playOverEnd() {
this.node.active = false; this.node.active = false;
......
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