Skip to content

Commit

Permalink
Prevent tween collisions when fading a FlxSound (HaxeFlixel#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeCreates authored and Aurel300 committed Apr 17, 2018
1 parent 8a5849b commit f6f620e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions flixel/system/FlxSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class FlxSound extends FlxBasic
* In case of looping, the point (in milliseconds) from where to restart the sound when it loops back
*/
public var loopTime:Float;
/**
* The tween used to fade this sounds volume in and out
*/
public var fadeTween:FlxTween;
/**
* Internal tracker for a Flash sound object.
*/
Expand Down Expand Up @@ -455,7 +459,11 @@ class FlxSound extends FlxBasic
*/
public inline function fadeOut(Duration:Float = 1, ?To:Float = 0, ?onComplete:FlxTween->Void):FlxSound
{
FlxTween.num(volume, To, Duration, { onComplete:onComplete }, volumeTween);
if (fadeTween != null)
{
fadeTween.cancel();
}
fadeTween = FlxTween.num(volume, To, Duration, { onComplete:onComplete }, volumeTween);

return this;
}
Expand All @@ -470,8 +478,14 @@ class FlxSound extends FlxBasic
public inline function fadeIn(Duration:Float = 1, From:Float = 0, To:Float = 1, ?onComplete:FlxTween->Void):FlxSound
{
if (!playing)
{
play();
FlxTween.num(From, To, Duration, { onComplete:onComplete }, volumeTween);
}
if (fadeTween != null)
{
fadeTween.cancel();
}
fadeTween = FlxTween.num(From, To, Duration, { onComplete:onComplete }, volumeTween);
return this;
}

Expand Down

0 comments on commit f6f620e

Please sign in to comment.