defined volume property on WebAudioSoundManager prototype

This commit is contained in:
Pavle Goloskokovic 2017-11-15 15:11:37 +01:00
parent 3820e75a5a
commit e5a5ee847f

View file

@ -5,13 +5,12 @@ var WebAudioSound = require('./WebAudioSound');
var WebAudioSoundManager = new Class({
Extends: BaseSoundManager,
initialize: function WebAudioSoundManager(game) {
BaseSoundManager.call(this, game);
/**
* The AudioContext being used for playback.
*
* @property {AudioContext} context
*/
this.context = this.createAudioContext();
this.context = this.createAudioContext(game);
/**
* [description]
*
@ -25,9 +24,10 @@ var WebAudioSoundManager = new Class({
*/
this.destination = this.masterVolumeNode;
this.masterVolumeNode.connect(this.context.destination);
BaseSoundManager.call(this, game);
},
createAudioContext: function () {
var audioConfig = this.game.config.audio;
createAudioContext: function (game) {
var audioConfig = game.config.audio;
if (audioConfig && audioConfig.context) {
return audioConfig.context;
}
@ -39,4 +39,16 @@ var WebAudioSoundManager = new Class({
return sound;
}
});
/**
* Global volume setting.
* @property {number} volume
*/
Object.defineProperty(WebAudioSoundManager.prototype, 'volume', {
get: function () {
return this.masterVolumeNode.gain.value;
},
set: function (value) {
this.masterVolumeNode.gain.value = value;
}
});
module.exports = WebAudioSoundManager;