playSound stop previous

This commit is contained in:
oc 2019-03-31 19:40:55 +08:00
parent 2cea5fccfc
commit 99a4a7b2a2
3 changed files with 8 additions and 4 deletions

View File

@ -1385,6 +1385,8 @@ async可选如果为true则会异步执行即不等待当前事件执行
值得注意的是如果是额外添加进文件的音效则需在main.js中this.sounds里加载它。 值得注意的是如果是额外添加进文件的音效则需在main.js中this.sounds里加载它。
可以加`"stop": true`来停止之前正在播放的音效。
### stopSound停止所有音效 ### stopSound停止所有音效
使用`{"type": "stopSound"}`可以停止所有音效。 使用`{"type": "stopSound"}`可以停止所有音效。

View File

@ -1481,15 +1481,16 @@ return code;
*/; */;
playSound_s playSound_s
: '播放音效' EvalString Newline : '播放音效' EvalString '停止之前音效' Bool? Newline
/* playSound_s /* playSound_s
tooltip : playSound: 播放音效 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 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 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; return code;
*/; */;
@ -2495,7 +2496,7 @@ ActionParser.prototype.parseAction = function() {
break; break;
case "playSound": case "playSound":
this.next = MotaActionBlocks['playSound_s'].xmlText([ this.next = MotaActionBlocks['playSound_s'].xmlText([
data.name,this.next]); data.name,data.stop,this.next]);
break; break;
case "playBgm": case "playBgm":
this.next = MotaActionBlocks['playBgm_s'].xmlText([ this.next = MotaActionBlocks['playBgm_s'].xmlText([

View File

@ -1213,6 +1213,7 @@ events.prototype._action_freeBgm = function (data, x, y, prefix) {
} }
events.prototype._action_playSound = function (data, x, y, prefix) { events.prototype._action_playSound = function (data, x, y, prefix) {
if (data.stop) core.stopSound();
core.playSound(data.name); core.playSound(data.name);
core.doAction(); core.doAction();
} }