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({ var WebAudioSoundManager = new Class({
Extends: BaseSoundManager, Extends: BaseSoundManager,
initialize: function WebAudioSoundManager(game) { initialize: function WebAudioSoundManager(game) {
BaseSoundManager.call(this, game);
/** /**
* The AudioContext being used for playback. * The AudioContext being used for playback.
* *
* @property {AudioContext} context * @property {AudioContext} context
*/ */
this.context = this.createAudioContext(); this.context = this.createAudioContext(game);
/** /**
* [description] * [description]
* *
@ -25,9 +24,10 @@ var WebAudioSoundManager = new Class({
*/ */
this.destination = this.masterVolumeNode; this.destination = this.masterVolumeNode;
this.masterVolumeNode.connect(this.context.destination); this.masterVolumeNode.connect(this.context.destination);
BaseSoundManager.call(this, game);
}, },
createAudioContext: function () { createAudioContext: function (game) {
var audioConfig = this.game.config.audio; var audioConfig = game.config.audio;
if (audioConfig && audioConfig.context) { if (audioConfig && audioConfig.context) {
return audioConfig.context; return audioConfig.context;
} }
@ -39,4 +39,16 @@ var WebAudioSoundManager = new Class({
return sound; 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; module.exports = WebAudioSoundManager;