Commit d7be4236 authored by jeff's avatar jeff

更新

parent 36c49c43
......@@ -30,7 +30,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
name: '填空区域',
action: {
type: 'text',
aduio: false,
audio: true,
option: [
['fontColor', '#000000'],
['fontSize', '100']
......
......@@ -14,7 +14,7 @@ cc.Class({
this._audioId = null
this._totoalTime = null
this._nowTime = null
this._pause == false
this._pause = false
},
onEnable() {
cc.systemEvent.on('stopBgMusic', this.onEvent, this)
......@@ -104,7 +104,6 @@ cc.Class({
this.pauseBtn.active = false
this.playBtn.active = true
this._play = false
this._pause = true
cc.audioEngine.pause(this._audioId)
},
......
......@@ -17,11 +17,13 @@ cc.Class({
onEnable() {
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this)
cc.systemEvent.on('changeAnswerState', this.onChangeState, this)
cc.systemEvent.on('stopWordsMusic', this.stopAudio, this)
},
onDisable() {
this.node.off(cc.Node.EventType.TOUCH_START, this.onTouchStart, this)
cc.systemEvent.off('changeAnswerState', this.onChangeState, this)
cc.systemEvent.off('stopWordsMusic', this.stopAudio, this)
},
initWithData(data, scale) {
......@@ -49,15 +51,52 @@ cc.Class({
},
onTouchStart() {
if (this._show) return
this._show = true
this.label.node.active = true
cc.audioEngine.play(this.tipClip)
if (this._playing) return
let url = this.data.actionData_.audio_url
if (this._show) {
if (url && url != '') {
cc.systemEvent.emit('stopBgMusic')
this.playAudio(url)
this._playing = true
} else {
this._playing = false
}
} else {
this._show = true
this.label.node.active = true
let id = cc.audioEngine.play(this.tipClip)
if (!url || url == '') {
this._playing = false
} else {
cc.audioEngine.setFinishCallback(id, this.playAudio.bind(this, url))
this._playing = true
}
}
},
/** 改变答案显示状态 */
onChangeState(show) {
this.label.node.active = show
this._show =show
}
this._show = show
if (!show) this._playing = false
},
/** 播放音乐 */
playAudio(url) {
cc.assetManager.loadRemote(url, (err, audioClip) => {
if (err) return
if (!this._playing) return
cc.systemEvent.emit('stopBgMusic')
this.audioId = cc.audioEngine.play(audioClip, false, 0.8);
cc.audioEngine.setFinishCallback(this.audioId, this.stopAudio.bind(this));
});
},
stopAudio() {
this._playing = false
if (this.audioId != null) {
cc.audioEngine.stop(this.audioId)
this.audioId = null
}
},
});
......@@ -109,7 +109,7 @@ cc.Class({
},
getDefaultData() {
const dataJson = ' [{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/5716af983b610b43b13efbdefec93a51.png","rect":{"x":222.44,"y":0,"width":903.11,"height":508},"bgAudioUrl":"http://staging-teach.cdn.ireadabc.com/c8a7dd49a778b0b6dd509aac0ef437ff.mp3","colorType":"1"},"hotZoneItemArr":[{"id":"1620909579034","index":0,"itemType":"text","fontScale":1.053125,"imgScale":1,"mapScale":1.053125,"gIdx":"0","actionData_":{"type":"text","changeOption":[["fontColor","#000000"],["fontSize","60"]],"text":"aaaaaaaaaaaaaa","audio_url":"http://staging-teach.cdn.ireadabc.com/c8a7dd49a778b0b6dd509aac0ef437ff.mp3"},"rect":{"width":520,"height":63.19,"x":22.44,"y":47.59}},{"id":"1620915585437","index":1,"pic_url":"http://staging-teach.cdn.ireadabc.com/31bde9b15582618fa5db4ac7cbc275b4.gif","itemType":"pic","fontScale":1.053125,"imgScale":0.14977973568281938,"mapScale":1.053125,"gIdx":"2","actionData_":{"type":"text","changeOption":[["fontColor","#000000"],["fontSize","100"]],"text":"bbbbbbbbbbb"},"rect":{"x":646.06,"y":45.93,"width":161.61,"height":68}},{"id":"1620920750092","index":2,"itemType":"text","fontScale":1.053125,"imgScale":1,"mapScale":1.053125,"gIdx":"0","actionData_":{"type":"text","changeOption":[["fontColor","#000000"],["fontSize","100"]],"text":"嗯?","audio_url":"http://staging-teach.cdn.ireadabc.com/7df4cc83a6c76dc6f0a526d07e6f1987.mp3"},"rect":{"width":210.62,"height":105.31,"x":362.26,"y":229.77}}]},{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/5716af983b610b43b13efbdefec93a51.png","bgAudioUrl":"http://staging-teach.cdn.ireadabc.com/8f73a6b73a217d25ca4f4a2e234c1513.mp3","rect":{"x":222.44,"y":0,"width":903.11,"height":508},"colorType":"1"},"hotZoneItemArr":[{"id":"1620920863432","index":0,"pic_url":"http://staging-teach.cdn.ireadabc.com/335dea1b83498b0c7c05be637dc13dad.jpeg","itemType":"text","fontScale":1.053125,"imgScale":0.22391857506361323,"mapScale":1.053125,"gIdx":"0","actionData_":{"type":"text","changeOption":[["fontColor","#FF0000"],["fontSize","100"]],"text":"This is a test"},"rect":{"width":558.89,"height":105.31,"x":13.12,"y":6.34}},{"id":"1620920877342","index":1,"itemType":"text","fontScale":1.053125,"imgScale":1,"mapScale":1.053125,"gIdx":"1","actionData_":{"type":"text","changeOption":[["fontColor","#0000FF"],["fontSize","100"]],"text":"you are so good"},"rect":{"width":734.29,"height":105.31,"x":106.44,"y":151.34}},{"id":"1620922839187","index":2,"itemType":"text","fontScale":1.053125,"imgScale":1,"mapScale":1.053125,"gIdx":"0","actionData_":{"type":"text","changeOption":[["fontColor","#000000"],["fontSize","100"]],"text":"_______________"},"rect":{"width":728.12,"height":105.31,"x":109.51,"y":170.34}}]}]'
const dataJson = '[{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/b90a006ba41723ec11970051e92f43e0.png","bgAudioUrl":"http://staging-teach.cdn.ireadabc.com/c8a7dd49a778b0b6dd509aac0ef437ff.mp3","rect":{"x":99.06,"y":0,"width":408.89,"height":230},"colorType":"0"},"hotZoneItemArr":[{"id":"1620920863432","index":0,"pic_url":"http://staging-teach.cdn.ireadabc.com/335dea1b83498b0c7c05be637dc13dad.jpeg","itemType":"text","fontScale":0.47421875,"imgScale":0.22391857506361323,"mapScale":0.47421875,"gIdx":"0","actionData_":{"type":"text","changeOption":[["fontColor","#FF0000"],["fontSize","100"]],"text":"This is a test"},"rect":{"width":251.66,"height":47.42,"x":6.6,"y":3}},{"id":"1620920877342","index":1,"itemType":"text","fontScale":0.47421875,"imgScale":1,"mapScale":0.47421875,"gIdx":"1","actionData_":{"type":"text","changeOption":[["fontColor","#0000FF"],["fontSize","100"]],"text":"you are so good","audio_url":"http://staging-teach.cdn.ireadabc.com/c8a7dd49a778b0b6dd509aac0ef437ff.mp3"},"rect":{"width":330.64,"height":47.42,"x":49.07,"y":68.65}},{"id":"1620922839187","index":2,"itemType":"text","fontScale":0.47421875,"imgScale":1,"mapScale":0.47421875,"gIdx":"0","actionData_":{"type":"text","changeOption":[["fontColor","#000000"],["fontSize","100"]],"text":"_______________"},"rect":{"width":327.86,"height":47.42,"x":50.46,"y":77.25}}]},{"bgItem":{"colorType":"0","url":"http://staging-teach.cdn.ireadabc.com/b90a006ba41723ec11970051e92f43e0.png","rect":{"x":222.44,"y":0,"width":903.11,"height":508}},"hotZoneItemArr":[{"id":"1621656703850","index":0,"itemType":"text","fontScale":1.053125,"imgScale":1,"mapScale":1.053125,"gIdx":"0","actionData_":{"type":"text","changeOption":[["fontColor","#0ff000"],["fontSize","45"]],"text":"I have someting to tell you","audio_url":"http://staging-teach.cdn.ireadabc.com/7df4cc83a6c76dc6f0a526d07e6f1987.mp3"},"rect":{"width":557.25,"height":47.39,"x":193.92,"y":24.3}},{"id":"1621656729516","index":1,"pic_url":"http://staging-teach.cdn.ireadabc.com/335dea1b83498b0c7c05be637dc13dad.jpeg","itemType":"pic","fontScale":1.053125,"imgScale":0.1679951320521704,"mapScale":1.053125,"gIdx":"2","rect":{"x":245.54,"y":161.8,"width":66.02,"height":134.4}},{"id":"1621656764791","index":2,"itemType":"text","fontScale":1.053125,"imgScale":1,"mapScale":1.053125,"gIdx":"1","actionData_":{"type":"text","changeOption":[["fontColor","#0000f0"],["fontSize","100"]],"text":"What?"},"rect":{"width":304.72,"height":105.31,"x":499.2,"y":165.34}}]}]'
const data = JSON.parse(dataJson);
return data;
},
......@@ -291,7 +291,7 @@ cc.Class({
return
}
picNode.getComponent('picNode').initWithData(data)
let url = data.bgItem.bgAudioUrl
if (url && url != '') {
this.bgAudioNode.active = true
......@@ -311,6 +311,7 @@ cc.Class({
cc.audioEngine.playEffect(this.tipClip)
} else {
cc.audioEngine.playEffect(this.btnClip)
cc.systemEvent.emit('stopWordsMusic')
}
this.checkNode.children[0].active = this.answerState
this.checkNode.children[1].active = !this.answerState
......
......@@ -64,9 +64,12 @@ cc.Class({
/** 播放音乐 */
playAudio(url) {
if (this._playing) return
this._playing = true
cc.assetManager.loadRemote(url, (err, audioClip) => {
if (err) return
if(playingItem) playingItem.stopAudio()
if (playingItem) playingItem.stopAudio()
if (!this._playing) return
this.audioId = cc.audioEngine.play(audioClip, false, 0.8);
cc.audioEngine.setFinishCallback(this.audioId, this.stopAudio.bind(this));
playingItem = this
......@@ -74,6 +77,7 @@ cc.Class({
},
stopAudio() {
this._playing = false
if (this.audioId != null) {
cc.audioEngine.stop(this.audioId)
this.audioId = 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