Sound.fadeTo allows you to fade the Sound to the given volume over the duration specified (thanks @nickryall #1225)

This commit is contained in:
photonstorm 2014-10-15 21:48:00 +01:00
parent 33ebc10570
commit 2657de0daa
2 changed files with 11 additions and 22 deletions

View file

@ -79,6 +79,7 @@ Version 2.1.3 - "Ravinda" - in development
* Updated to Pixi v2.0.0
* Happily removed the IE11 WebGL lock as Pixi now fully supports it :)
* Time.prevTime is a new property that contains the raw value of the game timer from the previous update.
* Sound.fadeTo allows you to fade the Sound to the given volume over the duration specified (thanks @nickryall #1225)
### Updates

View file

@ -793,12 +793,11 @@ Phaser.Sound.prototype = {
* and the final volume (1) as the second parameter.
*
* @method Phaser.Sound#fadeIn
* @param {number} [duration=1000] - The time in milliseconds during which the Sound should fade in.
* @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.
*/
fadeIn: function (duration, loop) {
if (typeof duration === 'undefined') { duration = 1000; }
if (typeof loop === 'undefined') { loop = false; }
if (this.paused)
@ -808,9 +807,7 @@ Phaser.Sound.prototype = {
this.play('', 0, 0, loop);
var tween = this.game.add.tween(this).to( { volume: 1 }, duration, Phaser.Easing.Linear.None, true);
tween.onComplete.add(this.fadeComplete, this);
this.fadeTo(duration, 1);
},
@ -820,20 +817,11 @@ Phaser.Sound.prototype = {
* and the final volume (0) as the second parameter.
*
* @method Phaser.Sound#fadeOut
* @param {number} [duration=1000] - The time in milliseconds during which the Sound should fade out.
* @param {number} [duration=1000] - The time in milliseconds over which the Sound should fade out.
*/
fadeOut: function (duration) {
if (typeof duration === 'undefined') { duration = 1000; }
if (!this.isPlaying || this.paused || this.volume <= 0)
{
return;
}
var tween = this.game.add.tween(this).to( { volume: 0 }, duration, Phaser.Easing.Linear.None, true);
tween.onComplete.add(this.fadeComplete, this);
this.fadeTo(duration, 0);
},
@ -844,10 +832,15 @@ Phaser.Sound.prototype = {
*
* @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.
* @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)
{
return;
}
if (typeof duration === 'undefined') { duration = 1000; }
if (typeof volume === 'undefined')
@ -856,11 +849,6 @@ Phaser.Sound.prototype = {
return;
}
if (!this.isPlaying || this.paused || volume === this.volume)
{
return;
}
var tween = this.game.add.tween(this).to( { volume: volume }, duration, Phaser.Easing.Linear.None, true);
tween.onComplete.add(this.fadeComplete, this);