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

feat: 点击胡萝卜发音

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