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

添加音频

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