Commit a3399e95 authored by 范雪寒's avatar 范雪寒

fix:

右下角播放/暂停按钮
正文字体最大宽度问题

refactor:
playAudio方法放入Game类中
parent f33b7255
...@@ -27,6 +27,14 @@ export class Game { ...@@ -27,6 +27,14 @@ export class Game {
} }
getAudioObj(key) {
return this._parent.audioObj[key];
}
playAudio(key, now = false, callback = null) {
this._parent.playAudio(key, now, callback);
}
addChild(node, z = 1) { addChild(node, z = 1) {
this._parent.renderArr.push(node); this._parent.renderArr.push(node);
......
...@@ -59,10 +59,10 @@ export class MyGame extends Game { ...@@ -59,10 +59,10 @@ export class MyGame extends Game {
} }
preLoadData(imgUrlList, audioUrlList) { preLoadData(imgUrlList, audioUrlList) {
imgUrlList.forEach((imgUrl)=>{ imgUrlList.forEach((imgUrl) => {
this._parent.addUrlToImages(imgUrl); this._parent.addUrlToImages(imgUrl);
}); });
audioUrlList.forEach((audioUrl)=>{ audioUrlList.forEach((audioUrl) => {
this._parent.addUrlToAudioObj(audioUrl); this._parent.addUrlToAudioObj(audioUrl);
}); });
} }
...@@ -207,6 +207,8 @@ export class MyGame extends Game { ...@@ -207,6 +207,8 @@ export class MyGame extends Game {
questionLabel.setPosition(...positionList[idx]); questionLabel.setPosition(...positionList[idx]);
questionLabel.setName('label_' + idx); questionLabel.setName('label_' + idx);
questionLabel.setMaxSize(this.typeDiff(400, 450));
questionLabel.addTouchBeganListener(() => { questionLabel.addTouchBeganListener(() => {
this.onClickWords(idx); this.onClickWords(idx);
}); });
...@@ -222,11 +224,17 @@ export class MyGame extends Game { ...@@ -222,11 +224,17 @@ export class MyGame extends Game {
speaker.init(this.images.get('Btn_play')); speaker.init(this.images.get('Btn_play'));
speaker.setPositionX(this.typeDiff(bookBg.width / 2, bookBg.width / 2 * 0.92)); speaker.setPositionX(this.typeDiff(bookBg.width / 2, bookBg.width / 2 * 0.92));
speaker.setPositionY(this.typeDiff(bookBg.height / 2, bookBg.height / 2 * 1.15)); speaker.setPositionY(this.typeDiff(bookBg.height / 2, bookBg.height / 2 * 1.15));
speaker.addTouchBeganListener(() => { speaker.addTouchBeganListener(() => this.onClickSpeaker(speaker));
this.onClickSpeaker(); speaker.setName('speaker');
jelly(speaker);
});
this.bg.addChild(speaker); this.bg.addChild(speaker);
const speakerPause = new TouchSprite();
speakerPause.init(this.images.get('Btn_pause'));
speakerPause.setPositionX(this.typeDiff(bookBg.width / 2, bookBg.width / 2 * 0.92));
speakerPause.setPositionY(this.typeDiff(bookBg.height / 2, bookBg.height / 2 * 1.15));
speakerPause.addTouchBeganListener(() => this.onClickSpeakerPause(speakerPause));
speakerPause.alpha = 0;
speakerPause.setName('speakerPause');
this.bg.addChild(speakerPause);
} }
createWindow() { createWindow() {
...@@ -248,10 +256,7 @@ export class MyGame extends Game { ...@@ -248,10 +256,7 @@ export class MyGame extends Game {
btnClose.init(this.images.get('Btn_close')); btnClose.init(this.images.get('Btn_close'));
btnClose.setPositionX(winBg.width / 2 * 0.93); btnClose.setPositionX(winBg.width / 2 * 0.93);
btnClose.setPositionY(-winBg.height / 2 * 0.9); btnClose.setPositionY(-winBg.height / 2 * 0.9);
btnClose.addTouchBeganListener(() => { btnClose.addTouchBeganListener(() => this.onClickCloseBtn(btnClose));
this.onClickCloseBtn();
jelly(btnClose);
});
btnClose.setName('btnClose'); btnClose.setName('btnClose');
btnClose.alpha = 0; btnClose.alpha = 0;
this.bg.addChild(btnClose); this.bg.addChild(btnClose);
...@@ -281,6 +286,7 @@ export class MyGame extends Game { ...@@ -281,6 +286,7 @@ export class MyGame extends Game {
onClickWords(idx) { onClickWords(idx) {
const label = this.bg.getChildByName('label_' + idx); const label = this.bg.getChildByName('label_' + idx);
this.playAudio('audio_new_window', true);
this.showWindow(this.data.words[idx], this.data.audios[idx], label); this.showWindow(this.data.words[idx], this.data.audios[idx], label);
} }
...@@ -302,7 +308,9 @@ export class MyGame extends Game { ...@@ -302,7 +308,9 @@ export class MyGame extends Game {
const btnClose = this.bg.getChildByName('btnClose'); const btnClose = this.bg.getChildByName('btnClose');
const wordLabel = winBg.getChildByName('wordLabel'); const wordLabel = winBg.getChildByName('wordLabel');
wordLabel.setScaleXY(1);
wordLabel.text = word; wordLabel.text = word;
wordLabel.setMaxSize(1000);
wordLabel.refreshSize(); wordLabel.refreshSize();
wordLabel.set('audio', audio); wordLabel.set('audio', audio);
wordLabel.alpha = 1; wordLabel.alpha = 1;
...@@ -323,14 +331,46 @@ export class MyGame extends Game { ...@@ -323,14 +331,46 @@ export class MyGame extends Game {
onClickWinWords() { onClickWinWords() {
const wordLabel = this.bg.seekChildByName('wordLabel'); const wordLabel = this.bg.seekChildByName('wordLabel');
this._parent.playAudio(wordLabel.get('audio')); this.playAudio(wordLabel.get('audio'));
}
onClickSpeaker(speaker) {
const speakerPause = this.bg.seekChildByName('speakerPause');
const audio = this.getAudioObj(this.data.wholeAuido);
audio.onended = () => this.showSpeaker(speaker, speakerPause);
audio.play();
this.showPauser(speaker, speakerPause);
jelly(speaker);
jelly(speakerPause);
} }
onClickSpeaker() { onClickSpeakerPause(speakerPause) {
this._parent.playAudio(this.data.wholeAuido); const speaker = this.bg.seekChildByName('speaker');
const audio = this.getAudioObj(this.data.wholeAuido);
audio.pause();
this.showSpeaker(speaker, speakerPause);
jelly(speaker);
jelly(speakerPause);
}
showSpeaker(speaker, speakerPause) {
tweenChange(speaker, { alpha: 1 }, 0.3);
tweenChange(speakerPause, { alpha: 0 }, 0.3);
}
showPauser(speaker, speakerPause) {
tweenChange(speaker, { alpha: 0 }, 0.3);
tweenChange(speakerPause, { alpha: 1 }, 0.3);
} }
onClickCloseBtn() { onClickCloseBtn(btn) {
jelly(btn);
this.playAudio('audio_close_widow');
this.hideWindow(); this.hideWindow();
} }
...@@ -339,7 +379,7 @@ export class MyGame extends Game { ...@@ -339,7 +379,7 @@ export class MyGame extends Game {
} }
onClickTittle() { onClickTittle() {
this._parent.playAudio(this.data.tittle.audio); this.playAudio(this.data.tittle.audio);
} }
gameStart() { gameStart() {
...@@ -347,6 +387,6 @@ export class MyGame extends Game { ...@@ -347,6 +387,6 @@ export class MyGame extends Game {
} }
playIncomeAudio() { playIncomeAudio() {
this._parent.playAudio('audio_new_page'); this.playAudio('audio_new_page');
} }
} }
const res = [ const res = [
['Btn_close', "assets/play/Btn_close.png"], ['Btn_close', "assets/play/Btn_close.png"],
['Btn_pause', "assets/play/Btn_pause.png"],
['Btn_play', "assets/play/Btn_play.png"], ['Btn_play', "assets/play/Btn_play.png"],
['Img_bg', "assets/play/Img_bg.png"], ['Img_bg', "assets/play/Img_bg.png"],
['Img_mask', "assets/play/Img_mask.png"], ['Img_mask', "assets/play/Img_mask.png"],
...@@ -9,6 +10,7 @@ const res = [ ...@@ -9,6 +10,7 @@ const res = [
['Img_whole_bg_type_B', "assets/play/Img_whole_bg_type_B.png"], ['Img_whole_bg_type_B', "assets/play/Img_whole_bg_type_B.png"],
['Img_winBg_type_A', "assets/play/Img_winBg_type_A.png"], ['Img_winBg_type_A', "assets/play/Img_winBg_type_A.png"],
['Img_winBg_type_B', "assets/play/Img_winBg_type_B.png"], ['Img_winBg_type_B', "assets/play/Img_winBg_type_B.png"],
]; ];
...@@ -22,6 +24,10 @@ const resAudio = [ ...@@ -22,6 +24,10 @@ const resAudio = [
['xxxbbbbcccc', "assets/play/default/xxxbbbbcccc.mp3"], ['xxxbbbbcccc', "assets/play/default/xxxbbbbcccc.mp3"],
['zzzzbbbbcccc', "assets/play/default/zzzzbbbbcccc.mp3"], ['zzzzbbbbcccc', "assets/play/default/zzzzbbbbcccc.mp3"],
['tittle', "assets/play/default/tittle.mp3"], ['tittle', "assets/play/default/tittle.mp3"],
['audio_new_page', "assets/play/audio_new_page.mp3"],
['audio_close_widow', "assets/play/audio_close_widow.mp3"],
['audio_new_window', "assets/play/audio_new_window.mp3"],
]; ];
export {res, resAudio}; export {res, resAudio};
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