Commit ce0e330e authored by 李维's avatar 李维

翻页时停止酷猫说话

parent 05c5c0b1
...@@ -183,6 +183,10 @@ cc.Class({ ...@@ -183,6 +183,10 @@ cc.Class({
}, },
onTouchLeft() { onTouchLeft() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!this.inited) return resolve('');
if (this.isTruning) {
return resolve('');
}
if (this.verletRender) { if (this.verletRender) {
return resolve(''); return resolve('');
} }
...@@ -195,6 +199,7 @@ cc.Class({ ...@@ -195,6 +199,7 @@ cc.Class({
GameData.isPlaying = 1; GameData.isPlaying = 1;
let page = this.pageList[GameData.pageIndex]; let page = this.pageList[GameData.pageIndex];
let itemPage = page.getComponent('ItemPage'); let itemPage = page.getComponent('ItemPage');
this.stopAllAudio();
itemPage.playAudio(); itemPage.playAudio();
itemPage.playSpine().then(() => { itemPage.playSpine().then(() => {
let nextPage = this.pageList[GameData.pageIndex + 1]; let nextPage = this.pageList[GameData.pageIndex + 1];
...@@ -209,6 +214,10 @@ cc.Class({ ...@@ -209,6 +214,10 @@ cc.Class({
}, },
onTouchRight() { onTouchRight() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!this.inited) return resolve('');
if (this.isTruning) {
return resolve('');
}
if (this.verletRender) { if (this.verletRender) {
return resolve(''); return resolve('');
} }
...@@ -226,6 +235,7 @@ cc.Class({ ...@@ -226,6 +235,7 @@ cc.Class({
} }
GameData.isPlaying = 2; GameData.isPlaying = 2;
let itemPage = page.getComponent('ItemPage'); let itemPage = page.getComponent('ItemPage');
this.stopAllAudio();
itemPage.playAudio(); itemPage.playAudio();
itemPage.playSpine().then(() => { itemPage.playSpine().then(() => {
if (this.pageList.length - GameData.pageIndex <= 2) { if (this.pageList.length - GameData.pageIndex <= 2) {
...@@ -407,6 +417,7 @@ cc.Class({ ...@@ -407,6 +417,7 @@ cc.Class({
if (this.isTruning) { if (this.isTruning) {
return false; return false;
} }
this.stopAllAudio();
if (GameData.isPlaying == 1) { if (GameData.isPlaying == 1) {
this.stopLeft(); this.stopLeft();
// return false; // return false;
...@@ -425,6 +436,7 @@ cc.Class({ ...@@ -425,6 +436,7 @@ cc.Class({
if (this.isTruning) { if (this.isTruning) {
return false; return false;
} }
this.stopAllAudio();
if (GameData.isPlaying) { if (GameData.isPlaying) {
this.stopLeft(); this.stopLeft();
this.stopRight(); this.stopRight();
...@@ -437,7 +449,6 @@ cc.Class({ ...@@ -437,7 +449,6 @@ cc.Class({
return true; return true;
}, },
catSpeakStart(cb) { catSpeakStart(cb) {
const cat = cc.find('Canvas/mao'); const cat = cc.find('Canvas/mao');
playDragonBoneAnimation(cat, 'begin', 0); playDragonBoneAnimation(cat, 'begin', 0);
...@@ -465,7 +476,6 @@ cc.Class({ ...@@ -465,7 +476,6 @@ cc.Class({
}); });
}, },
catSpeakEnd(cb) { catSpeakEnd(cb) {
const cat = cc.find('Canvas/mao'); const cat = cc.find('Canvas/mao');
playDragonBoneAnimation(cat, 'finish', 0); playDragonBoneAnimation(cat, 'finish', 0);
...@@ -478,10 +488,15 @@ cc.Class({ ...@@ -478,10 +488,15 @@ cc.Class({
}, },
onTouchCat() { onTouchCat() {
if (!this.inited) return resolve('');
if (this.isTruning) {
return resolve('');
}
this.catSpeakWait(() => { this.catSpeakWait(() => {
console.log("猫说话") console.log("猫说话")
}); });
}, },
catSpeakWait(cb) { catSpeakWait(cb) {
const cat = cc.find('Canvas/mao'); const cat = cc.find('Canvas/mao');
playDragonBoneAnimation(cat, 'begin', -1); playDragonBoneAnimation(cat, 'begin', -1);
...@@ -491,6 +506,13 @@ cc.Class({ ...@@ -491,6 +506,13 @@ cc.Class({
}); });
}, },
// 停止所有音频
stopAllAudio() {
const cat = cc.find('Canvas/mao');
cc.audioEngine.stopAll();
playDragonBoneAnimation(cat, 'normal', -1);
},
currentPlayedAudioId: null, currentPlayedAudioId: null,
stopCurrentPlayedAudio() { stopCurrentPlayedAudio() {
if (this.currentPlayedAudioId !== null) { if (this.currentPlayedAudioId !== null) {
...@@ -498,6 +520,7 @@ cc.Class({ ...@@ -498,6 +520,7 @@ cc.Class({
this.currentPlayedAudioId = null; this.currentPlayedAudioId = null;
} }
}, },
playEffect(name, cb) { playEffect(name, cb) {
this.stopCurrentPlayedAudio(); this.stopCurrentPlayedAudio();
const audioNode = cc.find(`audios/${name}`); const audioNode = cc.find(`audios/${name}`);
...@@ -517,6 +540,7 @@ cc.Class({ ...@@ -517,6 +540,7 @@ cc.Class({
this.playAudioQuestion(); this.playAudioQuestion();
}) })
}, },
playAudioPage(isBtn, cb) { playAudioPage(isBtn, cb) {
GameData.audioCount++; GameData.audioCount++;
let url = this.data.questionList[GameData.questionIndex].pageAudio; let url = this.data.questionList[GameData.questionIndex].pageAudio;
......
...@@ -39,6 +39,8 @@ cc.Class({ ...@@ -39,6 +39,8 @@ cc.Class({
btnRight: cc.Node, btnRight: cc.Node,
// verletRender: VerletRender, // verletRender: VerletRender,
capture: require('capture_to_web'), capture: require('capture_to_web'),
}, },
// 生命周期 onLoad // 生命周期 onLoad
...@@ -181,6 +183,10 @@ cc.Class({ ...@@ -181,6 +183,10 @@ cc.Class({
}, },
onTouchLeft() { onTouchLeft() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!this.inited) return resolve('');
if (this.isTruning) {
return resolve('');
}
if (this.verletRender) { if (this.verletRender) {
return resolve(''); return resolve('');
} }
...@@ -193,6 +199,7 @@ cc.Class({ ...@@ -193,6 +199,7 @@ cc.Class({
GameData.isPlaying = 1; GameData.isPlaying = 1;
let page = this.pageList[GameData.pageIndex]; let page = this.pageList[GameData.pageIndex];
let itemPage = page.getComponent('ItemPage'); let itemPage = page.getComponent('ItemPage');
this.stopAllAudio();
itemPage.playAudio(); itemPage.playAudio();
itemPage.playSpine().then(() => { itemPage.playSpine().then(() => {
let nextPage = this.pageList[GameData.pageIndex + 1]; let nextPage = this.pageList[GameData.pageIndex + 1];
...@@ -207,6 +214,10 @@ cc.Class({ ...@@ -207,6 +214,10 @@ cc.Class({
}, },
onTouchRight() { onTouchRight() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!this.inited) return resolve('');
if (this.isTruning) {
return resolve('');
}
if (this.verletRender) { if (this.verletRender) {
return resolve(''); return resolve('');
} }
...@@ -224,6 +235,7 @@ cc.Class({ ...@@ -224,6 +235,7 @@ cc.Class({
} }
GameData.isPlaying = 2; GameData.isPlaying = 2;
let itemPage = page.getComponent('ItemPage'); let itemPage = page.getComponent('ItemPage');
this.stopAllAudio();
itemPage.playAudio(); itemPage.playAudio();
itemPage.playSpine().then(() => { itemPage.playSpine().then(() => {
if (this.pageList.length - GameData.pageIndex <= 2) { if (this.pageList.length - GameData.pageIndex <= 2) {
...@@ -405,6 +417,7 @@ cc.Class({ ...@@ -405,6 +417,7 @@ cc.Class({
if (this.isTruning) { if (this.isTruning) {
return false; return false;
} }
this.stopAllAudio();
if (GameData.isPlaying == 1) { if (GameData.isPlaying == 1) {
this.stopLeft(); this.stopLeft();
// return false; // return false;
...@@ -423,6 +436,7 @@ cc.Class({ ...@@ -423,6 +436,7 @@ cc.Class({
if (this.isTruning) { if (this.isTruning) {
return false; return false;
} }
this.stopAllAudio();
if (GameData.isPlaying) { if (GameData.isPlaying) {
this.stopLeft(); this.stopLeft();
this.stopRight(); this.stopRight();
...@@ -476,6 +490,10 @@ cc.Class({ ...@@ -476,6 +490,10 @@ cc.Class({
}, },
onTouchCat() { onTouchCat() {
if (!this.inited) return resolve('');
if (this.isTruning) {
return resolve('');
}
this.catSpeakWait(() => { this.catSpeakWait(() => {
console.log("猫说话") console.log("猫说话")
}); });
...@@ -489,6 +507,13 @@ cc.Class({ ...@@ -489,6 +507,13 @@ cc.Class({
}); });
}, },
// 停止所有音频
stopAllAudio() {
const cat = cc.find('Canvas/mao');
cc.audioEngine.stopAll();
playDragonBoneAnimation(cat, 'normal', -1);
},
currentPlayedAudioId: null, currentPlayedAudioId: null,
stopCurrentPlayedAudio() { stopCurrentPlayedAudio() {
if (this.currentPlayedAudioId !== null) { if (this.currentPlayedAudioId !== null) {
......
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