setVolume
This commit is contained in:
1 parent
9beec9f3ce
commit
eafcfa4deb
6 files changed
+46
-2
No files matched your search
+4
-2
@@ -2110,6 +2110,7 @@ control.prototype.playBgm = function (bgm) {
|
||||
}
|
||||
// 播放当前BGM
|
||||
core.musicStatus.playingBgm = bgm;
|
||||
core.material.bgms[bgm].volume = core.musicStatus.volume;
|
||||
core.material.bgms[bgm].play();
|
||||
core.musicStatus.isPlaying = true;
|
||||
|
||||
@@ -2177,7 +2178,7 @@ control.prototype.playSound = function (sound) {
|
||||
if (core.musicStatus.audioContext != null) {
|
||||
var source = core.musicStatus.audioContext.createBufferSource();
|
||||
source.buffer = core.material.sounds[sound];
|
||||
source.connect(core.musicStatus.audioContext.destination);
|
||||
source.connect(core.musicStatus.gainNode);
|
||||
try {
|
||||
source.start(0);
|
||||
}
|
||||
@@ -2190,11 +2191,12 @@ control.prototype.playSound = function (sound) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.material.sounds[sound].volume = core.musicStatus.volume;
|
||||
core.material.sounds[sound].play();
|
||||
}
|
||||
}
|
||||
catch (eee) {
|
||||
console.log("无法播放SE "+bgm);
|
||||
console.log("无法播放SE "+sound);
|
||||
console.log(eee);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ function core() {
|
||||
'soundStatus': true, // 是否播放SE
|
||||
'playingBgm': null, // 正在播放的BGM
|
||||
'isPlaying': false,
|
||||
'gainNode': null,
|
||||
'volume': 1.0, // 音量
|
||||
}
|
||||
this.platform = {
|
||||
'isOnline': true, // 是否http
|
||||
@@ -187,6 +189,8 @@ core.prototype.init = function (coreData, callback) {
|
||||
window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext;
|
||||
try {
|
||||
core.musicStatus.audioContext = new window.AudioContext();
|
||||
core.musicStatus.gainNode = core.musicStatus.audioContext.createGain();
|
||||
core.musicStatus.gainNode.connect(core.musicStatus.audioContext.destination);
|
||||
} catch (e) {
|
||||
console.log("该浏览器不支持AudioContext");
|
||||
core.musicStatus.audioContext = null;
|
||||
|
||||
@@ -537,6 +537,17 @@ events.prototype.doAction = function() {
|
||||
core.resumeBgm();
|
||||
this.doAction();
|
||||
break
|
||||
case "setVolume":
|
||||
data.value = parseInt(data.value||0);
|
||||
if (data.value>100) data.value=100;
|
||||
data.value = data.value / 100;
|
||||
core.musicStatus.volume = data.value;
|
||||
if (core.isset(core.musicStatus.playingBgm)) {
|
||||
core.material.bgms[core.musicStatus.playingBgm].volume = data.value;
|
||||
}
|
||||
core.musicStatus.gainNode.gain.value = data.value;
|
||||
this.doAction();
|
||||
break;
|
||||
case "setValue":
|
||||
try {
|
||||
var value=core.calValue(data.value);
|
||||
|
||||
Reference in new issue
Block a user