Commit 6526bffd authored by 范雪寒's avatar 范雪寒

feat: 点击胡萝卜发音

parent e9b41469
......@@ -23,7 +23,14 @@
[picUrl]="it.carrotImg"
(imageUploaded)="onImageUploadSuccess($event, 'carrot', i)"
></app-upload-image-with-preview>
<br>
<span style="float: left; height: 30px; font-size: 18px;">胡萝卜发音:</span>
<br><br>
<app-audio-recorder
[audioUrl]="it.carrotAudio"
(audioUploaded)="onCarrotImgUploadSuccess($event, i)"
></app-audio-recorder>
<br>
<span style="float: left; height: 30px; font-size: 18px;">坑:</span>
<br><br>
<app-upload-image-with-preview
......
......@@ -23,11 +23,23 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.save();
}
addCarrot() {
addCarrot(saveFlg = true) {
this.item.carrots.push({
carrotImg: '',
carrotAudio: '',
holeImg: '',
});
if (saveFlg) {
this.save();
}
}
addTarget() {
this.item.targets.push({
targetImg: '',
x: 0,
y: -300
});
this.save();
}
......@@ -38,25 +50,14 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
text: "",
audio: ""
},
carrots: [{
carrotImg: '',
holeImg: '',
}, {
carrotImg: '',
holeImg: '',
}, {
carrotImg: '',
holeImg: '',
}, {
carrotImg: '',
holeImg: '',
}, {
carrotImg: '',
holeImg: '',
}],
carrots: [],
targets: []
};
for (var i = 0; i < 5; ++i) {
this.addCarrot(false);
}
// 获取存储的数据
(<any>window).courseware.getData((data) => {
......@@ -73,14 +74,6 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
}
addTarget() {
this.item.targets.push({
targetImg: '',
x: 0,
y: -300
});
}
deleteTarget(idx) {
this.item.targets.splice(idx, 1);
this.save();
......@@ -117,6 +110,10 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.item.targets[idx].targetImg = e.url;
this.save();
}
onCarrotImgUploadSuccess(e, idx) {
this.item.carrots[idx].carrotAudio = e.url;
this.save();
}
/**
* 储存音频数据
......
......@@ -49,15 +49,10 @@ export class MyGame extends Game {
let imgUrlList = [];
let audioUrlList = [];
this.data.carrots.forEach((carrot) => {
imgUrlList.push(carrot.carrotImg);
imgUrlList.push(carrot.holeImg);
});
this.data.targets.forEach((target) => {
imgUrlList.push(target.targetImg);
});
// audioUrlList.push(this.data.wholeAuido);
// audioUrlList.push(this.data.tittle.audio);
imgUrlList.push(...this.data.carrots.map(data => [data.carrotImg, data.holeImg]).flat(Infinity));
imgUrlList.push(...this.data.targets.map(data => data.targetImg));
audioUrlList.push(...this.data.carrots.map(data => data.carrotAudio));
audioUrlList.push(...this.data.targets.map(data => data.targetAudio));
this.preLoadData(imgUrlList, audioUrlList);
}
......@@ -198,7 +193,15 @@ export class MyGame extends Game {
carrotSp.setPositionX(this.bg.width / length * (idx - (length - 1) / 2));
carrotSp.setPositionY(-550);
this.bg.addChild(carrotSp);
carrotSp.addTouchBeganListener(() => {
this.onClickCarrot(idx);
});
});
}
onClickCarrot(idx) {
this.playAudio(this.data.carrots[idx].carrotAudio);
}
createHoles() {
......@@ -251,7 +254,7 @@ export class MyGame extends Game {
targetSp.set('startPos', { x: targetSp.x, y: targetSp.y });
} else {
tweenChange(targetSp, { alpha: 1 }, 0.2);
this.playAudio('click', true, () => {
this.playAudio('audio_right', true, () => {
this.playAudio(this.data.targets[idx].targetAudio);
});
}
......
......@@ -10,7 +10,8 @@ const res = [
const resAudio = [
// ['click', "assets/play/music/click.mp3"],
['audio_new_page', "assets/play/audio_new_page.mp3"],
['audio_right', "assets/play/audio_right.mp3"],
];
......
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