Sound.fadeTween is now used for Sound.fadeIn and Sound.fadeOut audio tweens.

Sound.stop and Sound.destroy now halt a fade tween if in effect.
This commit is contained in:
photonstorm 2015-01-28 17:17:44 +00:00
parent dc5d5c27a0
commit d37ffe6a8f
2 changed files with 24 additions and 3 deletions

View file

@ -69,6 +69,8 @@ Version 2.3.0 - "Tarabon" - in dev
### Updates
* TypeScript definitions fixes and updates (thanks @clark-stevenson @TimvdEijnden @belohlavek @ivw)
* Sound.fadeTween is now used for Sound.fadeIn and Sound.fadeOut audio tweens.
* Sound.stop and Sound.destroy now halt a fade tween if in effect.
### Bug Fixes

View file

@ -125,6 +125,11 @@ Phaser.Sound = function (game, key, volume, loop, connect) {
*/
this.currentMarker = '';
/**
* @property {Phaser.Tween} fadeTween - The tween that fades the audio, set via Sound.fadeIn and Sound.fadeOut.
*/
this.fadeTween = null;
/**
* @property {boolean} pendingPlayback - true if the sound file is pending playback
* @readonly
@ -421,6 +426,8 @@ Phaser.Sound.prototype = {
}
else
{
// console.log('Sound update stop: ' + this.currentTime + ' m: ' + this.currentMarker);
if (this.loop)
{
this.onLoop.dispatch(this);
@ -450,6 +457,8 @@ Phaser.Sound.prototype = {
if (typeof marker === 'undefined' || marker === false || marker === null) { marker = ''; }
if (typeof forceRestart === 'undefined') { forceRestart = true; }
// console.log('Sound play: ' + marker);
if (this.isPlaying && !this.allowMultiple && !forceRestart && !this.override)
{
// Use Restart instead
@ -514,10 +523,12 @@ Phaser.Sound.prototype = {
this._tempPosition = this.position;
this._tempVolume = this.volume;
this._tempLoop = this.loop;
// console.log('Marker pos: ' + this.position + ' duration: ' + this.duration + ' ms: ' + this.durationMS);
}
else
{
console.warn("Phaser.Sound.play: audio marker " + marker + " doesn't exist");
// console.warn("Phaser.Sound.play: audio marker " + marker + " doesn't exist");
return this;
}
}
@ -644,6 +655,8 @@ Phaser.Sound.prototype = {
this.currentTime = 0;
this.stopTime = this.startTime + this.durationMS;
this.onPlay.dispatch(this);
// console.log('stopTime: ' + this.stopTime + ' rs: ' + this._sound.readyState);
}
else
{
@ -780,6 +793,7 @@ Phaser.Sound.prototype = {
}
}
this.pendingPlayback = false;
this.isPlaying = false;
var prevMarker = this.currentMarker;
@ -860,9 +874,9 @@ Phaser.Sound.prototype = {
return;
}
var tween = this.game.add.tween(this).to( { volume: volume }, duration, Phaser.Easing.Linear.None, true);
this.fadeTween = this.game.add.tween(this).to( { volume: volume }, duration, Phaser.Easing.Linear.None, true);
tween.onComplete.add(this.fadeComplete, this);
this.fadeTween.onComplete.add(this.fadeComplete, this);
},
@ -895,6 +909,11 @@ Phaser.Sound.prototype = {
this.stop();
if (this.fadeTween !== null)
{
this.fadeTween.stop();
}
if (remove)
{
this.game.sound.remove(this);