diff --git a/src/Avalonia.Animation/AnimatorStateMachine`1.cs b/src/Avalonia.Animation/AnimatorStateMachine`1.cs index 21a9fe7a50..8bfdf8b04a 100644 --- a/src/Avalonia.Animation/AnimatorStateMachine`1.cs +++ b/src/Avalonia.Animation/AnimatorStateMachine`1.cs @@ -163,16 +163,16 @@ namespace Avalonia.Animation animationDirection == PlaybackDirection.AlternateReverse ? (currentIteration % 2 == 0) ? true : false : animationDirection == PlaybackDirection.Reverse ? true : false; - double x1 = delayFC; - double x2 = x1 + durationFC; + double delayEndpoint = delayFC; + double iterationEndpoint = delayEndpoint + durationFC; - if (delayFC > 0 & t >= 0 & t <= x1) + if (delayFC > 0 & t >= 0 & t <= delayEndpoint) { - if (currentIteration == 0 && delayBetweenIterations) + if (currentIteration == 0 || delayBetweenIterations) DoDelay(); } - else if (t >= x1 & t <= x2) + else if (t >= delayEndpoint & t <= iterationEndpoint) { var interpVal = t / durationFC; @@ -184,7 +184,7 @@ namespace Avalonia.Animation lastInterpValue = Interpolator(easedTime, neutralValue); targetObserver.OnNext(lastInterpValue); } - else if (t > x2 & (currentIteration + 1 > repeatCount & !isLooping)) + else if (t > iterationEndpoint & (currentIteration + 1 > repeatCount & !isLooping)) { DoComplete(); } diff --git a/src/Avalonia.Animation/Timing.cs b/src/Avalonia.Animation/Timing.cs index 3eddc0ac26..fb61e15f05 100644 --- a/src/Avalonia.Animation/Timing.cs +++ b/src/Avalonia.Animation/Timing.cs @@ -15,15 +15,17 @@ namespace Avalonia.Animation /// public static class Timing { - static ulong _transitionsFrameCount; static long _tickStartTimeStamp; static PlayState _globalState = PlayState.Run; + static long TicksPerFrame = Stopwatch.Frequency / FramesPerSecond; + /// /// The number of frames per second. /// public const int FramesPerSecond = 60; + /// /// The time span of each frame. /// @@ -39,17 +41,18 @@ namespace Avalonia.Animation var globalTimer = Observable.Interval(FrameTick, AvaloniaScheduler.Instance); + AnimationStateTimer = globalTimer .Select(_ => { return (_globalState, (Stopwatch.GetTimestamp() - _tickStartTimeStamp) - / (Stopwatch.Frequency / FramesPerSecond)); + / TicksPerFrame); }) .Publish() .RefCount(); TransitionsTimer = globalTimer - .Select(p => _transitionsFrameCount++) + .Select(p => p) .Publish() .RefCount(); } @@ -95,7 +98,7 @@ namespace Avalonia.Animation /// The parameter passed to a subsciber is the number of frames since the animation system was /// initialized. /// - public static IObservable TransitionsTimer + public static IObservable TransitionsTimer { get; } @@ -113,16 +116,14 @@ namespace Avalonia.Animation /// public static IObservable GetTransitionsTimer(Animatable control, TimeSpan duration, TimeSpan delay = default(TimeSpan)) { - var startTime = _transitionsFrameCount; - var _duration = (ulong)(duration.Ticks / FrameTick.Ticks); - var endTime = startTime + _duration; + var _duration = (duration.Ticks / FrameTick.Ticks); + var endTime = _duration; return TransitionsTimer .TakeWhile(x => x < endTime) - .Select(x => (double)(x - startTime) / _duration) + .Select(x => (double)x / _duration) .StartWith(0.0) .Concat(Observable.Return(1.0)); } - } -} +} \ No newline at end of file