Skip to content

Commit

Permalink
time setter for FlxSound. See issue HaxeFlixel#1792
Browse files Browse the repository at this point in the history
  • Loading branch information
Beeblerox authored and Aurel300 committed Apr 17, 2018
1 parent 98cf52a commit 4d2d6c0
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions flixel/system/FlxSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ class FlxSound extends FlxBasic
#end
/**
* The position in runtime of the music playback.
* If you set time while sound is playing then sound will immediately move to specified time position.
* If you set time while sound is paused then it will start playing from specified position only after you call resume() method.
*/
public var time(default, null):Float;
public var time(get, set):Float;
/**
* The sound group this sound belongs to
*/
Expand Down Expand Up @@ -121,6 +123,10 @@ class FlxSound extends FlxBasic
* Internal tracker for volume.
*/
private var _volume:Float;
/**
* Internal tracker for sound channel position.
*/
private var _time:Float = 0;
#if (sys && openfl_legacy)
/**
* Internal tracker for pitch.
Expand Down Expand Up @@ -167,7 +173,7 @@ class FlxSound extends FlxBasic
x = 0;
y = 0;

time = 0;
_time = 0;
_paused = false;
_volume = 1.0;
_volumeAdjust = 1.0;
Expand Down Expand Up @@ -226,7 +232,7 @@ class FlxSound extends FlxBasic
return;
}

time = _channel.position;
_time = _channel.position;

var radialMultiplier:Float = 1.0;

Expand Down Expand Up @@ -422,7 +428,7 @@ class FlxSound extends FlxBasic
{
if (_paused)
{
startSound(time);
startSound(_time);
}
return this;
}
Expand All @@ -436,7 +442,7 @@ class FlxSound extends FlxBasic
{
return this;
}
time = _channel.position;
_time = _channel.position;
_paused = true;
cleanup(false, false);
return this;
Expand Down Expand Up @@ -545,9 +551,9 @@ class FlxSound extends FlxBasic
return;
}

time = StartTime;
_time = StartTime;
_paused = false;
_channel = _sound.play(time, 0, _transform);
_channel = _sound.play(_time, 0, _transform);
if (_channel != null)
{
#if (sys && openfl_legacy)
Expand Down Expand Up @@ -609,7 +615,7 @@ class FlxSound extends FlxBasic

if (resetPosition)
{
time = 0;
_time = 0;
_paused = false;
}
}
Expand Down Expand Up @@ -707,6 +713,21 @@ class FlxSound extends FlxBasic
return _transform.pan = pan;
}

private inline function get_time():Float
{
return _time;
}

private function set_time(time:Float):Float
{
if (playing)
{
cleanup(false, true);
startSound(time);
}
return _time = time;
}

override public function toString():String
{
return FlxStringUtil.getDebugString([
Expand Down

0 comments on commit 4d2d6c0

Please sign in to comment.