bgmStatus
This commit is contained in:
parent
ba2f92572b
commit
5e563ab410
@ -31,7 +31,7 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
||||
"bgms": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_data": "在此存放所有的bgm,和文件名一致。第一项为默认播放项 \n音频名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好"
|
||||
"_data": "在此存放所有的bgm,和文件名一致。 \n音频名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好"
|
||||
},
|
||||
"sounds": {
|
||||
"_leaf": true,
|
||||
@ -62,6 +62,12 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
||||
"_range": "(thiseval instanceof Array && thiseval.length<=6)||thiseval==null",
|
||||
"_data": "装备位名称,为不超过6个的数组,此项的顺序与equiptype数值关联;例如可写[\"武器\",\"防具\",\"首饰\"]等等。"
|
||||
},
|
||||
"startBgm": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_string": true,
|
||||
"_data": "在标题界面应该播放的bgm内容"
|
||||
},
|
||||
"statusLeftBackground": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
|
||||
@ -144,8 +144,8 @@ editor_blockly = function () {
|
||||
MotaActionBlocks['screenFlash_s'].xmlText(),
|
||||
MotaActionBlocks['setWeather_s'].xmlText(),
|
||||
MotaActionBlocks['playBgm_s'].xmlText(),
|
||||
MotaActionBlocks['pauseBgm_s'].xmlText(),
|
||||
MotaActionBlocks['resumeBgm_s'].xmlText(),
|
||||
// MotaActionBlocks['pauseBgm_s'].xmlText(),
|
||||
// MotaActionBlocks['resumeBgm_s'].xmlText(),
|
||||
MotaActionBlocks['loadBgm_s'].xmlText(),
|
||||
MotaActionBlocks['freeBgm_s'].xmlText(),
|
||||
MotaActionBlocks['playSound_s'].xmlText(),
|
||||
|
||||
@ -374,7 +374,7 @@ floorId指定的是目标楼层的唯一标识符(ID)。
|
||||
要播放音乐和音效,你需要将对应的文件放在sounds目录下,然后在全塔属性中进行定义
|
||||
|
||||
``` js
|
||||
"bgms": [ // 在此存放所有的bgm,和文件名一致。第一项为默认播放项
|
||||
"bgms": [ // 在此存放所有的bgm,和文件名一致。
|
||||
// 音频名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好
|
||||
'bgm.mp3'
|
||||
];
|
||||
|
||||
@ -1256,10 +1256,14 @@ async可选,如果为true则会异步执行(即不等待当前事件执行
|
||||
|
||||
使用`{"type": "pauseBgm"}`可以暂停背景音乐的播放。
|
||||
|
||||
**从V2.5.4开始不再支持此事件,请通过设置音量来达到此效果。**
|
||||
|
||||
### resumeBgm:恢复背景音乐
|
||||
|
||||
使用`{"type": "resumeBgm"}`可以恢复背景音乐的播放。
|
||||
|
||||
**从V2.5.4开始不再支持此事件,请通过设置音量来达到此效果。**
|
||||
|
||||
### loadBgm:预加载一个背景音乐
|
||||
|
||||
使用loadBgm可以预加载一个背景音乐。
|
||||
|
||||
@ -1840,7 +1840,6 @@ actions.prototype.clickSwitchs = function (x,y) {
|
||||
core.resumeBgm();
|
||||
else {
|
||||
core.pauseBgm();
|
||||
core.musicStatus.playingBgm = null;
|
||||
}
|
||||
core.setLocalStorage('bgmStatus', core.musicStatus.bgmStatus);
|
||||
core.ui.drawSwitchs();
|
||||
|
||||
@ -432,8 +432,7 @@ control.prototype.resetStatus = function(hero, hard, floorId, route, maps, value
|
||||
////// 重新开始游戏;此函数将回到标题页面 //////
|
||||
control.prototype.restart = function(noAnimate) {
|
||||
this.showStartAnimate(noAnimate);
|
||||
if (core.bgms.length>0)
|
||||
core.playBgm(core.bgms[0]);
|
||||
core.playBgm(main.startBgm);
|
||||
}
|
||||
|
||||
|
||||
@ -2501,10 +2500,19 @@ control.prototype.unLockControl = function () {
|
||||
////// 播放背景音乐 //////
|
||||
control.prototype.playBgm = function (bgm) {
|
||||
if (main.mode!='play')return;
|
||||
// 如果不允许播放
|
||||
if (!core.musicStatus.bgmStatus) return;
|
||||
// 音频不存在
|
||||
if (!core.isset(core.material.bgms[bgm])) return;
|
||||
// 如果不允许播放
|
||||
if (!core.musicStatus.bgmStatus) {
|
||||
try {
|
||||
core.musicStatus.playingBgm = bgm;
|
||||
core.material.bgms[bgm].pause();
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
// 延迟播放
|
||||
@ -2518,11 +2526,11 @@ control.prototype.playBgm = function (bgm) {
|
||||
// 缓存BGM
|
||||
core.loader.loadBgm(bgm);
|
||||
// 如果当前正在播放,且和本BGM相同,直接忽略
|
||||
if (core.musicStatus.playingBgm == bgm && core.musicStatus.isPlaying) {
|
||||
if (core.musicStatus.playingBgm == bgm && !core.material.bgms[core.musicStatus.playingBgm].paused) {
|
||||
return;
|
||||
}
|
||||
// 如果正在播放中,暂停
|
||||
if (core.isset(core.musicStatus.playingBgm) && core.musicStatus.isPlaying) {
|
||||
if (core.isset(core.musicStatus.playingBgm)) {
|
||||
core.material.bgms[core.musicStatus.playingBgm].pause();
|
||||
}
|
||||
// 播放当前BGM
|
||||
@ -2530,7 +2538,6 @@ control.prototype.playBgm = function (bgm) {
|
||||
core.material.bgms[bgm].currentTime = 0;
|
||||
core.material.bgms[bgm].play();
|
||||
core.musicStatus.playingBgm = bgm;
|
||||
core.musicStatus.isPlaying = true;
|
||||
}
|
||||
catch (e) {
|
||||
console.log("无法播放BGM "+bgm);
|
||||
@ -2546,7 +2553,6 @@ control.prototype.pauseBgm = function () {
|
||||
if (core.isset(core.musicStatus.playingBgm)) {
|
||||
core.material.bgms[core.musicStatus.playingBgm].pause();
|
||||
}
|
||||
core.musicStatus.isPlaying = false;
|
||||
}
|
||||
catch (e) {
|
||||
console.log("无法暂停BGM");
|
||||
@ -2557,24 +2563,10 @@ control.prototype.pauseBgm = function () {
|
||||
////// 恢复背景音乐的播放 //////
|
||||
control.prototype.resumeBgm = function () {
|
||||
if (main.mode!='play')return;
|
||||
// 如果不允许播放
|
||||
if (!core.musicStatus.bgmStatus) return;
|
||||
|
||||
// 恢复BGM
|
||||
try {
|
||||
if (core.isset(core.musicStatus.playingBgm)) {
|
||||
core.material.bgms[core.musicStatus.playingBgm].play();
|
||||
core.musicStatus.isPlaying = true;
|
||||
}
|
||||
else {
|
||||
if (core.bgms.length>0) {
|
||||
if (core.isset(core.status.thisMap.bgm)) {
|
||||
core.playBgm(core.status.thisMap.bgm);
|
||||
}
|
||||
else
|
||||
core.playBgm(core.bgms[0]);
|
||||
}
|
||||
}
|
||||
core.playBgm(core.musicStatus.playingBgm);
|
||||
}
|
||||
catch (e) {
|
||||
console.log("无法恢复BGM");
|
||||
@ -2619,13 +2611,7 @@ control.prototype.playSound = function (sound) {
|
||||
}
|
||||
|
||||
control.prototype.checkBgm = function() {
|
||||
if (core.musicStatus.startDirectly && core.musicStatus.bgmStatus) {
|
||||
if (core.musicStatus.playingBgm==null
|
||||
|| core.material.bgms[core.musicStatus.playingBgm].paused) {
|
||||
core.musicStatus.playingBgm=null;
|
||||
core.playBgm(core.bgms[0]);
|
||||
}
|
||||
}
|
||||
core.playBgm(main.startBgm);
|
||||
}
|
||||
|
||||
////// 清空状态栏 //////
|
||||
|
||||
17
libs/core.js
17
libs/core.js
@ -50,11 +50,9 @@ function core() {
|
||||
}
|
||||
this.musicStatus = {
|
||||
'audioContext': null, // WebAudioContext
|
||||
'startDirectly': false, // 是否直接播放(加载)音乐
|
||||
'bgmStatus': false, // 是否播放BGM
|
||||
'soundStatus': true, // 是否播放SE
|
||||
'playingBgm': null, // 正在播放的BGM
|
||||
'isPlaying': false,
|
||||
'gainNode': null,
|
||||
'volume': 1.0, // 音量
|
||||
'cachedBgms': [], // 缓存BGM内容
|
||||
@ -310,24 +308,11 @@ core.prototype.init = function (coreData, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
if (core.platform.isPC) {
|
||||
// 如果是PC端直接加载
|
||||
core.musicStatus.startDirectly = true;
|
||||
}
|
||||
else {
|
||||
var connection = navigator.connection;
|
||||
if (core.isset(connection) && connection.type=='wifi')
|
||||
core.musicStatus.startDirectly = true;
|
||||
}
|
||||
|
||||
// 先从存储中读取BGM状态
|
||||
core.musicStatus.bgmStatus = core.getLocalStorage('bgmStatus', true);
|
||||
if (!core.musicStatus.startDirectly) // 如果当前网络环境不允许
|
||||
if (!core.platform.isPC && (navigator.connection||{}).type!='wifi')
|
||||
core.musicStatus.bgmStatus = false;
|
||||
// core.setLocalStorage('bgmStatus', core.musicStatus.bgmStatus);
|
||||
|
||||
core.musicStatus.soundStatus = core.getLocalStorage('soundStatus', true);
|
||||
core.setLocalStorage('soundStatus', core.musicStatus.soundStatus);
|
||||
|
||||
// switchs
|
||||
core.flags.battleAnimate = core.getLocalStorage('battleAnimate', core.flags.battleAnimate);
|
||||
|
||||
@ -912,7 +912,8 @@ events.prototype.doAction = function() {
|
||||
case "playBgm":
|
||||
core.playBgm(data.name);
|
||||
this.doAction();
|
||||
break
|
||||
break;
|
||||
/*
|
||||
case "pauseBgm":
|
||||
core.pauseBgm();
|
||||
this.doAction();
|
||||
@ -921,6 +922,7 @@ events.prototype.doAction = function() {
|
||||
core.resumeBgm();
|
||||
this.doAction();
|
||||
break
|
||||
*/
|
||||
case "loadBgm":
|
||||
if (core.platform.isPC)
|
||||
core.loadBgm(data.name);
|
||||
|
||||
@ -256,8 +256,7 @@ loader.prototype.loadMusic = function () {
|
||||
});
|
||||
|
||||
// 直接开始播放
|
||||
if (core.musicStatus.startDirectly && core.bgms.length>0)
|
||||
core.playBgm(core.bgms[0]);
|
||||
core.playBgm(main.startBgm);
|
||||
}
|
||||
|
||||
loader.prototype.loadOneMusic = function (name) {
|
||||
|
||||
@ -57,6 +57,7 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
|
||||
"武器",
|
||||
"盾牌"
|
||||
],
|
||||
"startBgm": "bgm.mp3",
|
||||
"statusLeftBackground": "url(project/images/ground.png) repeat",
|
||||
"statusTopBackground": "url(project/images/ground.png) repeat",
|
||||
"toolsBackground": "url(project/images/ground.png) repeat",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user