Commit 30c8eefc authored by 李维's avatar 李维

dev commit

parent 04ee877a
This diff is collapsed.
...@@ -140,34 +140,37 @@ export default class Cartoon { ...@@ -140,34 +140,37 @@ export default class Cartoon {
// Audio // Audio
playAudio(audio_url, cb = null) { playAudio(audio_url, cb = null) {
if (audio_url) { return new Promise((res, rej) => {
var urlreg=/^(?=^.{3,255}$)(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*([\?&]\w+=\w*)*$/ if (audio_url) {
if(urlreg.test(audio_url)) { var urlreg=/^(?=^.{3,255}$)(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*([\?&]\w+=\w*)*$/
cc.assetManager.loadRemote(audio_url, (err, audioClip) => { if(urlreg.test(audio_url)) {
if(cb) { cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
this.audioCallback[audio_url] = cb if(cb) {
} this.audioCallback[audio_url] = cb
const audioId = cc.audioEngine.play(audioClip, false, 1); }
const audio = cc.audioEngine.play(audioClip, false, 1);
if (cb) {
cc.audioEngine.setFinishCallback(audio, () => {
delete this.audioCallback[audio_url]
cb();
});
}
res(audio)
});
} else {
const audioNode = cc.find('Canvas/res/audio').getChildByName(audio_url).getComponent(cc.AudioSource);
const audio = cc.audioEngine.play(audioNode.clip, false, 1)
if (cb) { if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => { this.audioCallback[audio_url] = cb
cc.audioEngine.setFinishCallback(audio, () => {
delete this.audioCallback[audio_url] delete this.audioCallback[audio_url]
cb(); cb();
}); });
} }
}); res(audio)
} else {
const audioNode = cc.find('Canvas/res/audio').getChildByName(audio_url).getComponent(cc.AudioSource);
let audio = cc.audioEngine.play(audioNode.clip, false, 1)
if (cb) {
this.audioCallback[audio_url] = cb
cc.audioEngine.setFinishCallback(audio, () => {
delete this.audioCallback[audio_url]
cb();
});
} }
} }
})
}
} }
stopAllAudio(exceptUrls = []) { stopAllAudio(exceptUrls = []) {
......
...@@ -33,14 +33,17 @@ export default class GameLogic { ...@@ -33,14 +33,17 @@ export default class GameLogic {
this.g_cartoon.initLocalAudios([ this.g_cartoon.initLocalAudios([
"test_audio" "test_audio"
]) ])
this.initBGMusic();
this.initBg() this.initBg()
this.initNodes(); this.initNodes();
this.resetPosition(); this.resetPosition();
this.initBottomButtons();
this.initBirds();
this.initImageCards(); this.initImageCards();
this.initTitle(); this.initTitle();
this.loadQuestion(); this.loadQuestion();
this.initBottomButtons();
this.initMaskLayer(); this.initMaskLayer();
// this.initQuestionPannel(); // this.initQuestionPannel();
// this.initButtons(); // this.initButtons();
...@@ -86,6 +89,9 @@ export default class GameLogic { ...@@ -86,6 +89,9 @@ export default class GameLogic {
this.g_cartoon.initCartoonElement(`bottomButtons`, this.g_cartoon.getNodeByPath(`Canvas/bottomButtons`)); this.g_cartoon.initCartoonElement(`bottomButtons`, this.g_cartoon.getNodeByPath(`Canvas/bottomButtons`));
this.g_cartoon.initCartoonElement(`restart_button`, this.g_cartoon.getNodeByPath(`Canvas/bottomButtons/restart`)); this.g_cartoon.initCartoonElement(`restart_button`, this.g_cartoon.getNodeByPath(`Canvas/bottomButtons/restart`));
this.g_cartoon.initCartoonElement(`bird_1`, this.g_cartoon.getNodeByPath(`Canvas/bird_1`));
this.g_cartoon.initCartoonElement(`bird_2`, this.g_cartoon.getNodeByPath(`Canvas/bird_2`));
} }
initBg() { initBg() {
...@@ -102,6 +108,16 @@ export default class GameLogic { ...@@ -102,6 +108,16 @@ export default class GameLogic {
tree3.height = cc.winSize.height tree3.height = cc.winSize.height
} }
initBGMusic() {
if(this.g_formData.bgMusic) {
this.g_cartoon.playAudio(this.g_formData.bgMusic).then(bgMusic => {
console.log(bgMusic)
bgMusic.isLoop = true;
bgMusic.setVolume(0.3)
})
}
}
resetPosition() { resetPosition() {
const bgNodeTitle= cc.find('Canvas/title'); const bgNodeTitle= cc.find('Canvas/title');
const bgNodeSnow = cc.find('Canvas/bgMain/bg_snow'); const bgNodeSnow = cc.find('Canvas/bgMain/bg_snow');
...@@ -112,7 +128,7 @@ export default class GameLogic { ...@@ -112,7 +128,7 @@ export default class GameLogic {
const cardPos = [ const cardPos = [
{x: -500, y: 128}, {x: -250, y: 128}, {x: 0, y: 128}, {x: 250, y: 128}, {x: 500, y: 128}, {x: -500, y: 128}, {x: -250, y: 128}, {x: 0, y: 128}, {x: 250, y: 128}, {x: 500, y: 128},
{x: -500, y: -128}, {x: -250, y: -128}, {x: 0, y: -128}, {x: 250, y: -128}, {x: 500, y: -128} {x: -500, y: -114}, {x: -250, y: -114}, {x: 0, y: -114}, {x: 250, y: -114}, {x: 500, y: -114}
] ]
for(let index=0; index<10; index++) { for(let index=0; index<10; index++) {
...@@ -171,9 +187,14 @@ export default class GameLogic { ...@@ -171,9 +187,14 @@ export default class GameLogic {
card.open = true; card.open = true;
this.g_cartoon.getCartoonElement(`card_${imageContainer.cardIndex+1}_normal`).node.opacity = 0; this.g_cartoon.getCartoonElement(`card_${imageContainer.cardIndex+1}_normal`).node.opacity = 0;
this.g_cartoon.getCartoonElement(`card_${imageContainer.cardIndex+1}_selected`).node.opacity = 255; this.g_cartoon.getCartoonElement(`card_${imageContainer.cardIndex+1}_selected`).node.opacity = 255;
this.switchCard(this.m_currentQuestion, imageContainer.cardIndex, ()=>{ this.g_cartoon.getCartoonElement("bird_2").flyTo(imageContainer.cardIndex, ()=>{
this.loadQuestion() setTimeout(()=>{
}) this.switchCard(this.m_currentQuestion, imageContainer.cardIndex, ()=>{
this.loadQuestion()
})
}, 500)
})
} }
}) })
...@@ -230,9 +251,14 @@ export default class GameLogic { ...@@ -230,9 +251,14 @@ export default class GameLogic {
this.g_cartoon.tweenChange(bell2.node, {scaleX: 0, scaleY: 0}, 0.2, ()=>{ this.g_cartoon.tweenChange(bell2.node, {scaleX: 0, scaleY: 0}, 0.2, ()=>{
this.g_cartoon.tweenChange(card_2.node, {x: x_1, y: y_1}, 1, ()=>{ this.g_cartoon.tweenChange(card_2.node, {x: x_1, y: y_1}, 1, ()=>{
this.g_cartoon.tweenChange(bell2.node, {scaleX: 1, scaleY: 1}, 0.2, ()=>{ this.g_cartoon.tweenChange(bell2.node, {scaleX: 1, scaleY: 1}, 0.2, ()=>{
if(callback) { this.g_cartoon.getCartoonElement("bird_1").flyBack(()=>{
callback(); setTimeout(()=>{
} if(callback) {
callback();
}
}, 1500)
})
this.g_cartoon.getCartoonElement("bird_2").flyBack()
}); });
}); });
}); });
...@@ -335,6 +361,7 @@ export default class GameLogic { ...@@ -335,6 +361,7 @@ export default class GameLogic {
this.endGame() this.endGame()
} else { } else {
index = this.m_currentQuestionArray[this.m_currentQuestion] index = this.m_currentQuestionArray[this.m_currentQuestion]
this.g_cartoon.getCartoonElement("bird_1").flyTo(index)
this.g_cartoon.getCartoonElement(`card_${index+1}_normal`).node.opacity = 0; this.g_cartoon.getCartoonElement(`card_${index+1}_normal`).node.opacity = 0;
this.g_cartoon.getCartoonElement(`card_${index+1}_selected`).node.opacity = 255; this.g_cartoon.getCartoonElement(`card_${index+1}_selected`).node.opacity = 255;
} }
...@@ -386,7 +413,75 @@ export default class GameLogic { ...@@ -386,7 +413,75 @@ export default class GameLogic {
} }
initBirds() {
let bird_1 = this.g_cartoon.getCartoonElement("bird_1")
let bird_2 = this.g_cartoon.getCartoonElement("bird_2")
bird_1.flyTo = (cardIndex, callback)=>{
let card = this.g_cartoon.getCartoonElement(`card_${cardIndex+1}`)
const worldPos = cc.find("Canvas").convertToWorldSpaceAR(cc.v2(bird_1.node.x, bird_1.node.y));
const localPos = card.node.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y));
bird_1.node.x = localPos.x;
bird_1.node.y = localPos.y;
bird_1.node.parent = card.node;
this.g_cartoon.tweenChange(bird_1.node, {x: -80, y: 90}, 0.5, ()=>{
if(callback) {
callback()
}
})
}
bird_1.flyBack = (callback)=>{
let parent = bird_1.node.parent
const worldPos = parent.convertToWorldSpaceAR(cc.v2(bird_1.node.x, bird_1.node.y));
const localPos = cc.find("Canvas").convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y));
bird_1.node.x = localPos.x;
bird_1.node.y = localPos.y;
bird_1.node.parent = cc.find("Canvas");
this.g_cartoon.tweenChange(bird_1.node, {x: -100, y: -270}, 0.5, ()=>{
if(callback) {
callback()
}
})
}
bird_2.flyTo = (cardIndex, callback)=>{
let card = this.g_cartoon.getCartoonElement(`card_${cardIndex+1}`)
const worldPos = cc.find("Canvas").convertToWorldSpaceAR(cc.v2(bird_2.node.x, bird_2.node.y));
const localPos = card.node.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y));
bird_2.node.x = localPos.x;
bird_2.node.y = localPos.y;
bird_2.node.parent = card.node;
this.g_cartoon.tweenChange(bird_2.node, {x: 80, y: 90}, 0.5, ()=>{
if(callback) {
callback()
}
})
}
bird_2.flyBack = (callback)=>{
let parent = bird_2.node.parent
const worldPos = parent.convertToWorldSpaceAR(cc.v2(bird_2.node.x, bird_2.node.y));
const localPos = cc.find("Canvas").convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y));
bird_2.node.x = localPos.x;
bird_2.node.y = localPos.y;
bird_2.node.parent = cc.find("Canvas");
this.g_cartoon.tweenChange(bird_2.node, {x: 105, y: -280}, 0.5, ()=>{
if(callback) {
callback()
}
})
}
}
......
...@@ -88,7 +88,7 @@ cc.Class({ ...@@ -88,7 +88,7 @@ cc.Class({
getDefaultData() { getDefaultData() {
// const dataJson = '{"contentObj":{"version":"1.0","key":"DataKey_Sbox_FT_08","bgMusic":"","titleText":"TEstd","questionAudio_url":"","dataArray":[{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/06cc843598a912921f6ca3acfde6220b.png","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/571974922f6678111348a5643dba7e20.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/78579114773af12a7aec6723e3b9d475.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/c99e82e1c3f087c6dc0469e30c624f70.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/5b45c89ac9e899d76522767219b1346b.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/2e28eae8f0e0f01193da6f3677379ed3.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/fad2dac4f8b59a185dc30d42617c2ca8.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/6c3fca11052464102407f173e4a83db9.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ec82c796af801486548ae98623f614d2.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ac4b9422df1556f80ac5c3058cd3d670.png"}]}}' // const dataJson = '{"contentObj":{"version":"1.0","key":"DataKey_Sbox_FT_08","bgMusic":"","titleText":"TEstd","questionAudio_url":"","dataArray":[{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/06cc843598a912921f6ca3acfde6220b.png","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/571974922f6678111348a5643dba7e20.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/78579114773af12a7aec6723e3b9d475.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/c99e82e1c3f087c6dc0469e30c624f70.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/5b45c89ac9e899d76522767219b1346b.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/2e28eae8f0e0f01193da6f3677379ed3.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/fad2dac4f8b59a185dc30d42617c2ca8.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/6c3fca11052464102407f173e4a83db9.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ec82c796af801486548ae98623f614d2.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ac4b9422df1556f80ac5c3058cd3d670.png"}]}}'
const dataJson = '{"contentObj":{"version":"1.0","key":"DataKey_Sbox_FT_08","bgMusic":"","titleText":"TEstd","questionAudio_url":"","dataArray":[{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/06cc843598a912921f6ca3acfde6220b.png","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/571974922f6678111348a5643dba7e20.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/78579114773af12a7aec6723e3b9d475.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/c99e82e1c3f087c6dc0469e30c624f70.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/5b45c89ac9e899d76522767219b1346b.png"}]}}' const dataJson = '{"contentObj":{"version":"1.0","key":"DataKey_Sbox_FT_08","bgMusic":"http://staging-teach.cdn.ireadabc.com/ad58bae62ea02cf215ce7dee22df306f.mp3","titleText":"TEstd","questionAudio_url":"http://staging-teach.cdn.ireadabc.com/2bf96923b83ee0c5f20930386ce07384.mp3","dataArray":[{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/06cc843598a912921f6ca3acfde6220b.png","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/571974922f6678111348a5643dba7e20.png","audio_url":"http://staging-teach.cdn.ireadabc.com/ae7c0930a45d0ffc9f13182298e2be71.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/78579114773af12a7aec6723e3b9d475.png","audio_url":"http://staging-teach.cdn.ireadabc.com/c14938125a52096dc0be9fbbf6638cb2.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/c99e82e1c3f087c6dc0469e30c624f70.png","audio_url":"http://staging-teach.cdn.ireadabc.com/135c628899396df62c14567f46d61f3f.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/5b45c89ac9e899d76522767219b1346b.png","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/2e28eae8f0e0f01193da6f3677379ed3.png","audio_url":"http://staging-teach.cdn.ireadabc.com/cb0ac1d1bcdfdaf768f0a06d3fff37a3.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/fad2dac4f8b59a185dc30d42617c2ca8.png","audio_url":"http://staging-teach.cdn.ireadabc.com/9df3f14bc88bcffc49b6717c40428ed8.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/6c3fca11052464102407f173e4a83db9.png","audio_url":"http://staging-teach.cdn.ireadabc.com/d5a5ac2f45431a8a15492cb9f78e0396.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ec82c796af801486548ae98623f614d2.png","audio_url":"http://staging-teach.cdn.ireadabc.com/fb08783926362bf64232e2ec6966011d.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ac4b9422df1556f80ac5c3058cd3d670.png","audio_url":"http://staging-teach.cdn.ireadabc.com/fb08783926362bf64232e2ec6966011d.mp3"}]}}'
const data = JSON.parse(dataJson); const data = JSON.parse(dataJson);
return data; return data;
}, },
......
{
"ver": "2.3.5",
"uuid": "cc352754-2be1-4f75-ab54-326a8b6ece5f",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 73,
"height": 76,
"platformSettings": {},
"subMetas": {
"bird_1": {
"ver": "1.0.4",
"uuid": "82f92a4c-e168-4d0a-8edb-30e7ee1d8bd4",
"rawTextureUuid": "cc352754-2be1-4f75-ab54-326a8b6ece5f",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 73,
"height": 76,
"rawWidth": 73,
"rawHeight": 76,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "cef0cef7-2571-44f2-8b7a-420e45d940fc",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 77,
"height": 81,
"platformSettings": {},
"subMetas": {
"bird_2": {
"ver": "1.0.4",
"uuid": "f3bf912c-e1a9-4404-8928-8526d7b8b761",
"rawTextureUuid": "cef0cef7-2571-44f2-8b7a-420e45d940fc",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 77,
"height": 81,
"rawWidth": 77,
"rawHeight": 81,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "dc448b60-55e2-46fe-a384-c886577afe19",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 174,
"height": 164,
"platformSettings": {},
"subMetas": {
"bird_audio": {
"ver": "1.0.4",
"uuid": "5d32cf66-0356-477d-baa2-ab960bc8cae9",
"rawTextureUuid": "dc448b60-55e2-46fe-a384-c886577afe19",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 174,
"height": 164,
"rawWidth": 174,
"rawHeight": 164,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "568ea519-b799-472a-9123-38ecca930ea5",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 174,
"height": 164,
"platformSettings": {},
"subMetas": {
"bird_audio_1": {
"ver": "1.0.4",
"uuid": "9616fbc0-1fbe-4db7-ac7b-cfcc07d2031c",
"rawTextureUuid": "568ea519-b799-472a-9123-38ecca930ea5",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 174,
"height": 164,
"rawWidth": 174,
"rawHeight": 164,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
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