stopSound
This commit is contained in:
parent
b82f92196c
commit
7586b3fe45
@ -286,6 +286,7 @@ action
|
||||
| loadBgm_s
|
||||
| freeBgm_s
|
||||
| playSound_s
|
||||
| stopSound_s
|
||||
| setVolume_s
|
||||
| win_s
|
||||
| lose_s
|
||||
@ -1381,6 +1382,18 @@ var code = '{"type": "playSound", "name": "'+EvalString_0+'"},\n';
|
||||
return code;
|
||||
*/;
|
||||
|
||||
stopSound_s
|
||||
: '停止所有音效' Newline
|
||||
|
||||
|
||||
/* stopSound_s
|
||||
tooltip : stopSound: 停止所有音效
|
||||
helpUrl : https://h5mota.com/games/template/docs/#/event?id=stopSound%ef%bc%9a%e5%81%9c%e6%ad%a2%e6%89%80%e6%9c%89%e9%9f%b3%e6%95%88
|
||||
colour : this.soundColor
|
||||
var code = '{"type": "stopSound"},\n';
|
||||
return code;
|
||||
*/;
|
||||
|
||||
setVolume_s
|
||||
: '设置音量' Int '渐变时间' Int? '不等待执行完毕' Bool Newline
|
||||
|
||||
@ -2326,6 +2339,10 @@ ActionParser.prototype.parseAction = function() {
|
||||
this.next = MotaActionBlocks['freeBgm_s'].xmlText([
|
||||
data.name,this.next]);
|
||||
break
|
||||
case "stopSound":
|
||||
this.next = MotaActionBlocks['stopSound_s'].xmlText([
|
||||
this.next]);
|
||||
break
|
||||
case "setVolume":
|
||||
this.next = MotaActionBlocks['setVolume_s'].xmlText([
|
||||
data.value, data.time||0, data.async||false, this.next]);
|
||||
|
||||
@ -141,6 +141,7 @@ editor_blockly = function () {
|
||||
MotaActionBlocks['loadBgm_s'].xmlText(),
|
||||
MotaActionBlocks['freeBgm_s'].xmlText(),
|
||||
MotaActionBlocks['playSound_s'].xmlText(),
|
||||
MotaActionBlocks['stopSound_s'].xmlText(),
|
||||
MotaActionBlocks['setVolume_s'].xmlText(),
|
||||
MotaActionBlocks['callBook_s'].xmlText(),
|
||||
MotaActionBlocks['callSave_s'].xmlText(),
|
||||
|
||||
@ -1306,6 +1306,12 @@ async可选,如果为true则会异步执行(即不等待当前事件执行
|
||||
|
||||
值得注意的是,如果是额外添加进文件的音效,则需在main.js中this.sounds里加载它。
|
||||
|
||||
### stopSound:停止所有音效
|
||||
|
||||
使用`{"type": "stopSound"}`可以停止所有音效。
|
||||
|
||||
这在人物对话音效时很有用。
|
||||
|
||||
### setVolume:设置音量
|
||||
|
||||
使用setVolume可以设置音量大小。
|
||||
|
||||
@ -2667,6 +2667,11 @@ control.prototype.playSound = function (sound) {
|
||||
var source = core.musicStatus.audioContext.createBufferSource();
|
||||
source.buffer = core.material.sounds[sound];
|
||||
source.connect(core.musicStatus.gainNode);
|
||||
source.loop = true;
|
||||
var id = parseInt(Math.random()*10000000);
|
||||
source.onended = function () {
|
||||
delete core.musicStatus.playingSounds[id];
|
||||
}
|
||||
try {
|
||||
source.start(0);
|
||||
}
|
||||
@ -2676,8 +2681,10 @@ control.prototype.playSound = function (sound) {
|
||||
}
|
||||
catch (ee) {
|
||||
main.log(ee);
|
||||
return;
|
||||
}
|
||||
}
|
||||
core.musicStatus.playingSounds[id] = source;
|
||||
}
|
||||
else {
|
||||
core.material.sounds[sound].volume = core.musicStatus.volume;
|
||||
|
||||
@ -54,6 +54,7 @@ function core() {
|
||||
'soundStatus': true, // 是否播放SE
|
||||
'playingBgm': null, // 正在播放的BGM
|
||||
'gainNode': null,
|
||||
'playingSounds': {}, // 正在播放的SE
|
||||
'volume': 1.0, // 音量
|
||||
'cachedBgms': [], // 缓存BGM内容
|
||||
'cachedBgmCount': 4, // 缓存的bgm数量
|
||||
|
||||
@ -959,6 +959,22 @@ events.prototype.doAction = function() {
|
||||
core.freeBgm(data.name);
|
||||
this.doAction();
|
||||
break;
|
||||
case "stopSound":
|
||||
for (var i in core.musicStatus.playingSounds) {
|
||||
var source = core.musicStatus.playingSounds[i];
|
||||
try {
|
||||
source.stop();
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
source.noteOff(0);
|
||||
}
|
||||
catch (e) {
|
||||
main.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "setVolume":
|
||||
data.value = core.clamp(parseInt(data.value)/100, 0, 1);
|
||||
core.setFlag("__volume__", data.value);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user