stopSound

This commit is contained in:
oc 2019-02-03 18:55:39 +08:00
parent 7586b3fe45
commit 8d7365b683
3 changed files with 23 additions and 15 deletions

View File

@ -2667,7 +2667,6 @@ control.prototype.playSound = function (sound) {
var source = core.musicStatus.audioContext.createBufferSource(); var source = core.musicStatus.audioContext.createBufferSource();
source.buffer = core.material.sounds[sound]; source.buffer = core.material.sounds[sound];
source.connect(core.musicStatus.gainNode); source.connect(core.musicStatus.gainNode);
source.loop = true;
var id = parseInt(Math.random()*10000000); var id = parseInt(Math.random()*10000000);
source.onended = function () { source.onended = function () {
delete core.musicStatus.playingSounds[id]; delete core.musicStatus.playingSounds[id];
@ -2697,6 +2696,23 @@ control.prototype.playSound = function (sound) {
} }
} }
control.prototype.stopSound = function () {
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);
}
}
}
}
control.prototype.checkBgm = function() { control.prototype.checkBgm = function() {
core.playBgm(core.musicStatus.playingBgm || main.startBgm); core.playBgm(core.musicStatus.playingBgm || main.startBgm);
} }

View File

@ -1502,6 +1502,11 @@ core.prototype.playSound = function (sound) {
core.control.playSound(sound); core.control.playSound(sound);
} }
////// 停止所有音效 //////
core.prototype.stopSound = function () {
core.control.stopSound();
}
////// 动画显示某对象 ////// ////// 动画显示某对象 //////
core.prototype.show = function (obj, speed, callback) { core.prototype.show = function (obj, speed, callback) {
core.utils.show(obj, speed, callback); core.utils.show(obj, speed, callback);

View File

@ -960,20 +960,7 @@ events.prototype.doAction = function() {
this.doAction(); this.doAction();
break; break;
case "stopSound": case "stopSound":
for (var i in core.musicStatus.playingSounds) { core.stopSound();
var source = core.musicStatus.playingSounds[i];
try {
source.stop();
}
catch (e) {
try {
source.noteOff(0);
}
catch (e) {
main.log(e);
}
}
}
break; break;
case "setVolume": case "setVolume":
data.value = core.clamp(parseInt(data.value)/100, 0, 1); data.value = core.clamp(parseInt(data.value)/100, 0, 1);