Skip to content

Commit d37ffe6

Browse files
committed
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.
1 parent dc5d5c2 commit d37ffe6

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Version 2.3.0 - "Tarabon" - in dev
6969
### Updates
7070

7171
* TypeScript definitions fixes and updates (thanks @clark-stevenson @TimvdEijnden @belohlavek @ivw)
72+
* Sound.fadeTween is now used for Sound.fadeIn and Sound.fadeOut audio tweens.
73+
* Sound.stop and Sound.destroy now halt a fade tween if in effect.
7274

7375
### Bug Fixes
7476

src/sound/Sound.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ Phaser.Sound = function (game, key, volume, loop, connect) {
125125
*/
126126
this.currentMarker = '';
127127

128+
/**
129+
* @property {Phaser.Tween} fadeTween - The tween that fades the audio, set via Sound.fadeIn and Sound.fadeOut.
130+
*/
131+
this.fadeTween = null;
132+
128133
/**
129134
* @property {boolean} pendingPlayback - true if the sound file is pending playback
130135
* @readonly
@@ -421,6 +426,8 @@ Phaser.Sound.prototype = {
421426
}
422427
else
423428
{
429+
// console.log('Sound update stop: ' + this.currentTime + ' m: ' + this.currentMarker);
430+
424431
if (this.loop)
425432
{
426433
this.onLoop.dispatch(this);
@@ -450,6 +457,8 @@ Phaser.Sound.prototype = {
450457
if (typeof marker === 'undefined' || marker === false || marker === null) { marker = ''; }
451458
if (typeof forceRestart === 'undefined') { forceRestart = true; }
452459

460+
// console.log('Sound play: ' + marker);
461+
453462
if (this.isPlaying && !this.allowMultiple && !forceRestart && !this.override)
454463
{
455464
// Use Restart instead
@@ -514,10 +523,12 @@ Phaser.Sound.prototype = {
514523
this._tempPosition = this.position;
515524
this._tempVolume = this.volume;
516525
this._tempLoop = this.loop;
526+
527+
// console.log('Marker pos: ' + this.position + ' duration: ' + this.duration + ' ms: ' + this.durationMS);
517528
}
518529
else
519530
{
520-
console.warn("Phaser.Sound.play: audio marker " + marker + " doesn't exist");
531+
// console.warn("Phaser.Sound.play: audio marker " + marker + " doesn't exist");
521532
return this;
522533
}
523534
}
@@ -644,6 +655,8 @@ Phaser.Sound.prototype = {
644655
this.currentTime = 0;
645656
this.stopTime = this.startTime + this.durationMS;
646657
this.onPlay.dispatch(this);
658+
659+
// console.log('stopTime: ' + this.stopTime + ' rs: ' + this._sound.readyState);
647660
}
648661
else
649662
{
@@ -780,6 +793,7 @@ Phaser.Sound.prototype = {
780793
}
781794
}
782795

796+
this.pendingPlayback = false;
783797
this.isPlaying = false;
784798
var prevMarker = this.currentMarker;
785799

@@ -860,9 +874,9 @@ Phaser.Sound.prototype = {
860874
return;
861875
}
862876

863-
var tween = this.game.add.tween(this).to( { volume: volume }, duration, Phaser.Easing.Linear.None, true);
877+
this.fadeTween = this.game.add.tween(this).to( { volume: volume }, duration, Phaser.Easing.Linear.None, true);
864878

865-
tween.onComplete.add(this.fadeComplete, this);
879+
this.fadeTween.onComplete.add(this.fadeComplete, this);
866880

867881
},
868882

@@ -895,6 +909,11 @@ Phaser.Sound.prototype = {
895909

896910
this.stop();
897911

912+
if (this.fadeTween !== null)
913+
{
914+
this.fadeTween.stop();
915+
}
916+
898917
if (remove)
899918
{
900919
this.game.sound.remove(this);

0 commit comments

Comments
 (0)