Commit 81f5dddc authored by Tt's avatar Tt

基础流程完成

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