From 5d6a46837ea68d23243926269cd2ba6062e04985 Mon Sep 17 00:00:00 2001 From: Maxwell Talbot Date: Wed, 30 Sep 2020 09:41:17 +0100 Subject: [PATCH 1/2] initialize _time to workStart where provided --- lib/src/rive_core/animation/linear_animation_instance.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/rive_core/animation/linear_animation_instance.dart b/lib/src/rive_core/animation/linear_animation_instance.dart index 1b1465f..64328f7 100644 --- a/lib/src/rive_core/animation/linear_animation_instance.dart +++ b/lib/src/rive_core/animation/linear_animation_instance.dart @@ -5,7 +5,12 @@ class LinearAnimationInstance { final LinearAnimation animation; double _time = 0; int direction = 1; - LinearAnimationInstance(this.animation); + + LinearAnimationInstance(this.animation) + : _time = + (animation.enableWorkArea ? animation.workStart : 0).toDouble() / + animation.fps; + double get time => _time; set time(double value) { if (_time == value) { From 951a4251f2824ab9b306c04fffafbe4913c7c569 Mon Sep 17 00:00:00 2001 From: Maxwell Talbot Date: Wed, 30 Sep 2020 09:42:17 +0100 Subject: [PATCH 2/2] stop the stopwatch if we are no longer advancing the animations, so they do not jump to an unintended timepoint when restarted --- lib/src/rive_render_box.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/rive_render_box.dart b/lib/src/rive_render_box.dart index 851240a..4a4e0d2 100644 --- a/lib/src/rive_render_box.dart +++ b/lib/src/rive_render_box.dart @@ -92,6 +92,7 @@ abstract class RiveRenderBox extends RenderBox { void _frameCallback(Duration duration) { _elapsedSeconds = _stopwatch.elapsedTicks / _stopwatch.frequency; _stopwatch.reset(); + _stopwatch.start(); markNeedsPaint(); } @@ -109,6 +110,8 @@ abstract class RiveRenderBox extends RenderBox { _frameCallbackId = null; if (advance(_elapsedSeconds)) { scheduleRepaint(); + } else { + _stopwatch.stop(); } _elapsedSeconds = 0;