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

fix:

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

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