diff --git a/_docs/event.md b/_docs/event.md index 3beb965a..cb8f7b82 100644 --- a/_docs/event.md +++ b/_docs/event.md @@ -1385,6 +1385,8 @@ async可选,如果为true则会异步执行(即不等待当前事件执行 值得注意的是,如果是额外添加进文件的音效,则需在main.js中this.sounds里加载它。 +可以加`"stop": true`来停止之前正在播放的音效。 + ### stopSound:停止所有音效 使用`{"type": "stopSound"}`可以停止所有音效。 diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index bb3e0f44..2555b855 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -1481,15 +1481,16 @@ return code; */; playSound_s - : '播放音效' EvalString Newline + : '播放音效' EvalString '停止之前音效' Bool? Newline /* playSound_s tooltip : playSound: 播放音效 helpUrl : https://h5mota.com/games/template/docs/#/event?id=playsound%EF%BC%9A%E6%92%AD%E6%94%BE%E9%9F%B3%E6%95%88 -default : ["item.mp3"] +default : ["item.mp3",false] colour : this.soundColor -var code = '{"type": "playSound", "name": "'+EvalString_0+'"},\n'; +Bool_0 = Bool_0 ? ', "stop": true' : ''; +var code = '{"type": "playSound", "name": "'+EvalString_0+'"'+Bool_0+'},\n'; return code; */; @@ -2495,7 +2496,7 @@ ActionParser.prototype.parseAction = function() { break; case "playSound": this.next = MotaActionBlocks['playSound_s'].xmlText([ - data.name,this.next]); + data.name,data.stop,this.next]); break; case "playBgm": this.next = MotaActionBlocks['playBgm_s'].xmlText([ diff --git a/libs/events.js b/libs/events.js index 768cc35d..bfabdb3c 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1213,6 +1213,7 @@ events.prototype._action_freeBgm = function (data, x, y, prefix) { } events.prototype._action_playSound = function (data, x, y, prefix) { + if (data.stop) core.stopSound(); core.playSound(data.name); core.doAction(); }