When setting a global volume for the SoundManager it would previously incorrectly calculate the volumes of AudioTag based Sound objects that were not played at volume 1. The new approach uses Sound.updateGlobalVolume which adjusts the Sound volume to be a percentage of the global volume. So if the global volume is 0.5 and the Sound volume is 0.5, the Sound will play with an actual volume of 0.25 (thanks @VitaZheltyakov #2325)

This commit is contained in:
photonstorm 2016-04-06 01:19:32 +01:00
parent 71056ccb69
commit 988290631f
3 changed files with 56 additions and 32 deletions

View file

@ -347,6 +347,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* Camera.follow now uses the Targets `world` property to seed the camera coordinates from, rather than its local position. This means Sprites that are members of offset Groups, or transformed display lists, should now be followed more accurately (thanks @rbozan #2106)
* PluginManager.destroy is now called by Game.destroy.
* Game.forceSingleUpdate is now `true` by default.
* Video now uses MediaStreamTrack.stop() instead of MediaStream.stop() where possible, as the later is now deprecated in some browsers (thanks @stoneman1 #2371)
### Bug Fixes
@ -364,6 +365,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* Arcade.Body's speed property was only set when the body moved, it now updates regardless (thanks @mark-henry #2417)
* Camera.position would return the view rectangles centerX/Y coordinates, instead of view.x/y (which is what Camera.x/y returns), so it has been updated to return view.x/y instead (thanks @kamparR #2120)
* Passing a BitmapData to a TileSprite as a texture would fail if the BitmapData had not been previously added to the cache. It now uses the new frameData property (thanks @mzamateo @lucap86 #2380)
* When setting a global volume for the SoundManager it would previously incorrectly calculate the volumes of AudioTag based Sound objects that were not played at volume 1. The new approach uses Sound.updateGlobalVolume which adjusts the Sound volume to be a percentage of the global volume. So if the global volume is 0.5 and the Sound volume is 0.5, the Sound will play with an actual volume of 0.25 (thanks @VitaZheltyakov #2325)
### Pixi Updates

View file

@ -901,17 +901,17 @@ Phaser.Sound.prototype = {
},
/**
* Starts this sound playing (or restarts it if already doing so) and sets the volume to zero.
* Then increases the volume from 0 to 1 over the duration specified.
*
* At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter,
* and the final volume (1) as the second parameter.
*
* @method Phaser.Sound#fadeIn
* @param {number} [duration=1000] - The time in milliseconds over which the Sound should fade in.
* @param {boolean} [loop=false] - Should the Sound be set to loop? Note that this doesn't cause the fade to repeat.
* @param {string} [marker=(current marker)] - The marker to start at; defaults to the current (last played) marker. To start playing from the beginning specify specify a marker of `''`.
*/
* Starts this sound playing (or restarts it if already doing so) and sets the volume to zero.
* Then increases the volume from 0 to 1 over the duration specified.
*
* At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter,
* and the final volume (1) as the second parameter.
*
* @method Phaser.Sound#fadeIn
* @param {number} [duration=1000] - The time in milliseconds over which the Sound should fade in.
* @param {boolean} [loop=false] - Should the Sound be set to loop? Note that this doesn't cause the fade to repeat.
* @param {string} [marker=(current marker)] - The marker to start at; defaults to the current (last played) marker. To start playing from the beginning specify specify a marker of `''`.
*/
fadeIn: function (duration, loop, marker) {
if (loop === undefined) { loop = false; }
@ -929,13 +929,13 @@ Phaser.Sound.prototype = {
},
/**
* Decreases the volume of this Sound from its current value to 0 over the duration specified.
* At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter,
* and the final volume (0) as the second parameter.
*
* @method Phaser.Sound#fadeOut
* @param {number} [duration=1000] - The time in milliseconds over which the Sound should fade out.
*/
* Decreases the volume of this Sound from its current value to 0 over the duration specified.
* At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter,
* and the final volume (0) as the second parameter.
*
* @method Phaser.Sound#fadeOut
* @param {number} [duration=1000] - The time in milliseconds over which the Sound should fade out.
*/
fadeOut: function (duration) {
this.fadeTo(duration, 0);
@ -943,14 +943,14 @@ Phaser.Sound.prototype = {
},
/**
* Fades the volume of this Sound from its current value to the given volume over the duration specified.
* At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter,
* and the final volume (volume) as the second parameter.
*
* @method Phaser.Sound#fadeTo
* @param {number} [duration=1000] - The time in milliseconds during which the Sound should fade out.
* @param {number} [volume] - The volume which the Sound should fade to. This is a value between 0 and 1.
*/
* Fades the volume of this Sound from its current value to the given volume over the duration specified.
* At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter,
* and the final volume (volume) as the second parameter.
*
* @method Phaser.Sound#fadeTo
* @param {number} [duration=1000] - The time in milliseconds during which the Sound should fade out.
* @param {number} [volume] - The volume which the Sound should fade to. This is a value between 0 and 1.
*/
fadeTo: function (duration, volume) {
if (!this.isPlaying || this.paused || volume === this.volume)
@ -973,11 +973,11 @@ Phaser.Sound.prototype = {
},
/**
* Internal handler for Sound.fadeIn, Sound.fadeOut and Sound.fadeTo.
*
* @method Phaser.Sound#fadeComplete
* @private
*/
* Internal handler for Sound.fadeIn, Sound.fadeOut and Sound.fadeTo.
*
* @method Phaser.Sound#fadeComplete
* @private
*/
fadeComplete: function () {
this.onFadeComplete.dispatch(this, this.volume);
@ -989,6 +989,28 @@ Phaser.Sound.prototype = {
},
/**
* Called automatically by SoundManager.volume.
*
* Sets the volume of AudioTag Sounds as a percentage of the Global Volume.
*
* You should not normally call this directly.
*
* @method Phaser.Sound#updateGlobalVolume
* @protected
* @param {float} globalVolume - The global SoundManager volume.
*/
updateGlobalVolume: function (globalVolume) {
// this._volume is the % of the global volume this sound should be played at
if (this.usingAudioTag && this._sound)
{
this._sound.volume = globalVolume * this._volume;
}
},
/**
* Destroys this sound and all associated events and removes it from the SoundManager.
*

View file

@ -830,7 +830,7 @@ Object.defineProperty(Phaser.SoundManager.prototype, "volume", {
{
if (this._sounds[i].usingAudioTag)
{
this._sounds[i].volume = value;
this._sounds[i].updateGlobalVolume(value);
}
}
}