Commit b83b2d6b authored by 李维's avatar 李维

添加酷猫讲话动画

parent 9cec5578
import { onHomeworkFinish } from "../script/util";
import { onHomeworkFinish, playDragonBoneAnimation } from "../script/util";
import { defaultData } from "../script/defaultData";
import { itemData } from "./data";
import { hyLoader } from "./hyLoader";
......@@ -300,8 +300,10 @@ cc.Class({
this.initLayout()//完成后直接进入下一步
})
} else {
this.coolCatSpeak();
pg.audio.playAudioByUrl(this._cat.start).then(() => {
this._catStartPlayed = true;
this.coolCatShutOut();
pg.view.loadDB(carton, { ske: this._stageData.cartoonSke, tex: this._stageData.cartoonTex, png: this._stageData.cartoonPng }).then((animationName) => {
this.animationName = animationName;
GameManager.getIns().setState(1);
......@@ -420,9 +422,11 @@ cc.Class({
let btn_picture = pg.view.find(this, "btn_picture");
// 一局失败弹出tryagain,同时下方录音按钮明亮并出现提示
this.coolCatSpeak("wrong")
this.playSFX("audio_tryagain").then(() => {
pg.view.visible(bg_tryagain, false);
pg.view.visible(end, false);
this.coolCatShutOut();
})
pg.view.visible(end, true);
pg.view.visible(bg_tryagain, true);
......@@ -433,8 +437,10 @@ cc.Class({
this._playing = true;
this._tryagainCount++;
this._timeoutIds.push(setTimeout(() => {
this.coolCatSpeak();
if (this._tryagainCount == 1) {
pg.audio.playAudioByUrl(this._tryagain.one).then(() => {
this.coolCatShutOut();
this._playing = false;
})
// this.playSFX("audio_record");
......@@ -447,6 +453,7 @@ cc.Class({
action.start();
} else if (this._tryagainCount == 2) {
pg.audio.playAudioByUrl(this._tryagain.two).then(() => {
this.coolCatShutOut();
this._playing = false;
})
// this.playSFX("audio_record");
......@@ -459,6 +466,7 @@ cc.Class({
action.start();
} else {
pg.audio.playAudioByUrl(this._tryagain.three).then(() => {
this.coolCatShutOut();
this._playing = false;
this.nextStage();
})
......@@ -486,8 +494,10 @@ cc.Class({
pg.view.visible(end_success, false);
pg.view.visible(bg_tryagain, false);
pg.audio.playAudioByUrl(this._cat.finish)
this.coolCatSpeak()
pg.audio.playAudioByUrl(this._cat.finish).then(()=>{
this.coolCatShutOut();
})
// this.playSFX("audio_finish");
// pg.view.visible(btn_picture, true);
pg.view.visible(btn_record, false);
......@@ -551,7 +561,9 @@ cc.Class({
resolve('');
}
})
this.coolCatSpeak();
pg.audio.playAudioByUrl(this._stageData.sound).then(() => {
this.coolCatShutOut();
audioFinished = true;
if (aniFinished && audioFinished) {
this._playing = false;
......@@ -571,7 +583,9 @@ cc.Class({
resolve('');
}
})
this.coolCatSpeak();
pg.audio.playAudioByUrl(this._stageData.sound).then(() => {
this.coolCatShutOut();
audioFinished = true;
if (aniFinished && audioFinished) {
this._playing = false;
......@@ -608,7 +622,9 @@ cc.Class({
resolve("");
} else {
this._audio_record = true;
this.coolCatSpeak();
pg.audio.playAudioByUrl(this._cat.record).then(() => {
this.coolCatShutOut();
this._playing = false;
resolve('');
})
......@@ -708,6 +724,7 @@ cc.Class({
onTouchRecord() {
if (this._playing) {
cc.audioEngine.stopAllEffects();
this.coolCatShutOut();
}
this.playSFX("audio_btns");
let end = pg.view.find(this, "end");
......@@ -797,14 +814,18 @@ cc.Class({
if (GameManager.getIns().getState() >= 5) {
if (this._playing) return;
this._playing = true;
this.coolCatSpeak("finish");
pg.audio.playAudioByUrl(this._cat.finish).then(() => {
this._playing = false;
this.coolCatShutOut();
})
} else {
if (this._playing) return;
this._playing = true;
this.coolCatSpeak();
pg.audio.playAudioByUrl(this._cat.wait).then(() => {
this._playing = false;
this.coolCatShutOut();
})
}
},
......@@ -833,10 +854,21 @@ cc.Class({
this.resultArr.push({ word, score, audio_url });
},
// 酷猫讲话动画
coolCatSpeak(aniName="begin") {
const cat = cc.find('Canvas/mao_ske');
console.log(playDragonBoneAnimation)
playDragonBoneAnimation(cat, aniName, -1);
return () => {
playDragonBoneAnimation(cat, 'noraml', -1);
}
},
// 酷猫闭嘴
coolCatShutOut() {
const cat = cc.find('Canvas/mao_ske');
playDragonBoneAnimation(cat, 'normal', -1);
},
onTouchIconRecord() {
......@@ -929,7 +961,10 @@ cc.Class({
//
onTouchVoice(touch) {
let item = touch.target;
pg.audio.playAudioByUrl(item.data.audio_url);
this.coolCatSpeak();
pg.audio.playAudioByUrl(item.data.audio_url).then(()=>{
this.coolCatShutOut();
})
},
//回合结束
groupEnd() {
......@@ -1044,9 +1079,11 @@ cc.Class({
var anim = pg.view.find(item, `audio`).getComponent(cc.Animation);
anim.play();
//如果没有audio也要能正常走
this.coolCatSpeak();
pg.audio.playAudioByUrl(item.data.audio).then(() => {
anim.stop();
pg.view.visible(pg.view.find(item, `audio/btn_laba`), true);
this.coolCatShutOut();
resolve('');
});
});
......
......@@ -347,3 +347,19 @@ export function onHomeworkFinish(data) {
console.log('onHomeworkFinish');
}
}
export function playDragonBoneAnimation(node, animationName, time = 1, onFinish = null, onFrameEvent = null) {
const armatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
armatureDisplay.timeScale = 1;
armatureDisplay.once(dragonBones.EventObject.COMPLETE, () => {
if (onFinish) {
onFinish();
}
});
armatureDisplay.on(dragonBones.EventObject.FRAME_EVENT, (event) => {
if (onFrameEvent) {
onFrameEvent(event);
}
});
armatureDisplay.playAnimation(animationName, time);
}
\ No newline at end of file
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