Commit 3719ae1b authored by 李维's avatar 李维

添加音频

parent 3bc543da
...@@ -80,7 +80,7 @@ cc.Class({ ...@@ -80,7 +80,7 @@ cc.Class({
// onLoad () {}, // onLoad () {},
_timeoutID: null, _timeoutID: null,
isStop: true, isStop: null,
start() {}, start() {},
init(audio_url, testTime) { init(audio_url, testTime) {
this.audioBeforeTest = audio_url; this.audioBeforeTest = audio_url;
...@@ -120,6 +120,8 @@ cc.Class({ ...@@ -120,6 +120,8 @@ cc.Class({
let url = this.recordWaitCount == 0 ? this.audioBeforeTest : ""; let url = this.recordWaitCount == 0 ? this.audioBeforeTest : "";
let cat = cc.find("cat", catBase); let cat = cc.find("cat", catBase);
asyncPlayDragonBoneAnimation(cat, "begin", 0); asyncPlayDragonBoneAnimation(cat, "begin", 0);
// 录音前停止所有音频
cc.audioEngine.stopAll();
playAudioByUrl(url, () => { playAudioByUrl(url, () => {
if(this.isStop) { if(this.isStop) {
return return
......
...@@ -27,7 +27,7 @@ const MSG_PLAYER_TO_HOME = "msg_player_to_home"; ...@@ -27,7 +27,7 @@ const MSG_PLAYER_TO_HOME = "msg_player_to_home";
const MSG_PROFIX_END = "__END__"; const MSG_PROFIX_END = "__END__";
const DEBUG = false; const DEBUG = false;
const TOTAL_SCORE = 42; // 总分 - 双方分数之和等于 TOTAL_SCORE const TOTAL_SCORE = 42; // 总分 - 双方分数之和等于 TOTAL_SCORE
const AI_SUCCESS_RATE = 0.7; // ai评测成功率 const AI_SUCCESS_RATE = 0.65; // ai评测成功率
const AUTO_GAME = false; // 自动游戏-调试使用 const AUTO_GAME = false; // 自动游戏-调试使用
@ccclass @ccclass
...@@ -45,9 +45,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -45,9 +45,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
networkHelper: NetworkHelper; networkHelper: NetworkHelper;
playerId; // 当前玩家ID playerId; // 当前玩家ID
isRoomOwner; // 是否为房主 isRoomOwner; // 是否为房主
recordWaitCount; // 录音等待倒计时
withAiPlayer=false; // 对手是否AI withAiPlayer=false; // 对手是否AI
gameEnd = false; gameEnd = false;
gameStaring = false;
addPreloadImage() { addPreloadImage() {
// TODO 根据自己的配置预加载图片资源 // TODO 根据自己的配置预加载图片资源
...@@ -58,6 +58,16 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -58,6 +58,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
addPreloadAudio() { addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源 // TODO 根据自己的配置预加载音频资源
// this._audioResList.push({ url: this.data.audio_url }); // this._audioResList.push({ url: this.data.audio_url });
// 游戏加载
this._audioResList.push({ url: this.data.gameLoadingAudio });
// 游戏开始
this._audioResList.push({ url: this.data.gameStartAudio });
// 提示录音
this._audioResList.push({ url: this.data.recordWait });
this._audioResList.push({ url: this.data.waitingPiece });
this._audioResList.push({ url: this.data.waitingTurn });
this._audioResList.push({ url: this.data.waitingWheel });
} }
addPreloadAnima() {} addPreloadAnima() {}
...@@ -103,7 +113,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -103,7 +113,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.server.onAIEvents = this.onAiEvents.bind(this); this.server.onAIEvents = this.onAiEvents.bind(this);
} }
await this.initHeadImgAndName(); await this.initHeadImgAndName();
this.recordWaitCount = 0;
} }
// 获取用户头像 // 获取用户头像
...@@ -202,6 +211,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -202,6 +211,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.initSide(); this.initSide();
this.timerHandle = this.initTimer(); this.timerHandle = this.initTimer();
this.initPlayerInfo(); this.initPlayerInfo();
this.coolcatSpeak(this.data.gameStartAudio, "begin", ()=>{
this.gameStaring = true;
});
// 自动游戏模式 - 调试使用 // 自动游戏模式 - 调试使用
if(AUTO_GAME) { if(AUTO_GAME) {
this.turntable.stopBlink(); this.turntable.stopBlink();
...@@ -209,6 +221,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -209,6 +221,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.runEvent(MSG_ROLLING, {nextGem: nextGem}); this.runEvent(MSG_ROLLING, {nextGem: nextGem});
} }
}); });
this.coolcatSpeak(this.data.gameLoadingAudio, "begin");
} }
// 初始化掉线提示组件 // 初始化掉线提示组件
...@@ -262,8 +275,23 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -262,8 +275,23 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 初始化酷猫 // 初始化酷猫
coolCat = null; coolCat = null;
coolCatClick = null;
coolCatAudioUrl = null;
initCoolCat() { initCoolCat() {
this.coolCat = cc.find("Canvas/coolcatLand/coolcat"); this.coolCat = cc.find("Canvas/coolcatLand/coolcat");
this.coolCatClick = cc.find("Canvas/coolcatLand/click");
this.coolCatAudioUrl = this.data.waitingWheel;
this.coolCatClick.on(cc.Node.EventType.TOUCH_END, ()=>{
if(this.gameStaring) {
if(this.side == this.currentGameSide) {
if(this.coolCatAudioUrl) {
this.coolcatSpeak(this.coolCatAudioUrl, "right")
}
} else {
this.coolcatSpeak(this.data.waitingTurn, "right")
}
}
})
} }
seagull = null; seagull = null;
...@@ -866,6 +894,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -866,6 +894,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.turntable.initTurntable(DEBUG); this.turntable.initTurntable(DEBUG);
cc.find("Canvas/Turntable").on("Rolling_Start", ()=>{ cc.find("Canvas/Turntable").on("Rolling_Start", ()=>{
// 游戏流程1: 玩家点击转盘 // 游戏流程1: 玩家点击转盘
if(!this.gameStaring) {
return;
}
this.turntable.stopBlink(); this.turntable.stopBlink();
const nextGem = this.getNextQuestionIndex(); const nextGem = this.getNextQuestionIndex();
this.runEvent(MSG_ROLLING, {nextGem: nextGem}); this.runEvent(MSG_ROLLING, {nextGem: nextGem});
...@@ -939,6 +970,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -939,6 +970,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 换边 // 换边
this.registerEvent(MSG_SWITCHSIDE, (param, next)=>{ this.registerEvent(MSG_SWITCHSIDE, (param, next)=>{
this.currentGameSide = param.side; this.currentGameSide = param.side;
this.coolCatAudioUrl = this.data.waitingWheel;
this.handleSwitchSide(); this.handleSwitchSide();
next(); next();
}) })
...@@ -1003,6 +1035,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1003,6 +1035,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 转盘 // 转盘
this.registerEvent(MSG_ROLLING, (param, next)=>{ this.registerEvent(MSG_ROLLING, (param, next)=>{
// console.log("转盘结果:", param.nextGem) // console.log("转盘结果:", param.nextGem)
cc.audioEngine.stopAll();
this.coolCatAudioUrl = this.data.waitingPiece;
this.turntable.stopBlink(); this.turntable.stopBlink();
this.turntable.rollNum(param.nextGem.score).then(()=>{ this.turntable.rollNum(param.nextGem.score).then(()=>{
// 异步操作执行完成后调用 // 异步操作执行完成后调用
...@@ -1242,4 +1276,25 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1242,4 +1276,25 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 重置转盘 // 重置转盘
this.turntable.reset(); this.turntable.reset();
} }
// 酷猫说话
audioID = null;
coolcatSpeak(url, aniName = "normal", callback?) {
if(url) {
console.log(aniName)
asyncPlayDragonBoneAnimation(this.coolCat, aniName, 0);
if(this.audioID) {
cc.audioEngine.stop(this.audioID);
}
this.playAudioByUrl(url, ()=>{
this.audioID=null;
if(callback) {
callback();
}
}).then(id=>{
this.audioID = id;
asyncPlayDragonBoneAnimation(this.coolCat, "normal", 0);
})
}
}
} }
export const defaultData = { export const defaultData = {
gameStartAudio: "gameStartAudio": "http://teach.cdn.ireadabc.com/46e8423adee1bde0837a26b84ea50e47.mp3",
"", "gameLoadingAudio": "http://teach.cdn.ireadabc.com/bb7f56145cabe28ce47e8a9280af58a3.mp3",
gameLoadingAudio: "waitingWheel": "http://teach.cdn.ireadabc.com/b50c22ab7d113d0f56cdeb327c88d2a9.mp3",
"", "waitingPiece": "http://teach.cdn.ireadabc.com/05cd6b07a5222b70320167224d33b397.mp3",
waitingWheel: "waitingTurn": "http://teach.cdn.ireadabc.com/6bfd2437056b32967bf0830b45b2e6ae.mp3",
"", "recordWait": "http://staging-teach.cdn.ireadabc.com/31952573236dd316a8ee1672d1614a1c.mp3"
waitingPiece: }
"",
waitingTurn:
"",
recordWait: "http://staging-teach.cdn.ireadabc.com/31952573236dd316a8ee1672d1614a1c.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