rive-flutter icon indicating copy to clipboard operation
rive-flutter copied to clipboard

How do I reset an animation to the beginning?

Open JacoFourie opened this issue 3 years ago • 10 comments

Hi all.

Thank you for building Rive. I have been playing with it and seems to do all I need. I have one question? If I have a animation that loops all the time, how do I set it back to the start after I set its active state to false? I want the animation to go to the start once I stopped it. Then when I start the animation again it should start from the start. If I set Active to false and later to true again it continues where it left off. I want to reset it. I have used the reset() method but it does nothing when I stop the animation. It seems when I start it again it will start at the beginning but once I stop it it stays where it was stopped.

JacoFourie avatar Aug 28 '21 21:08 JacoFourie

Is there a way??

JacoFourie avatar Sep 02 '21 14:09 JacoFourie

Hi @JacoFourie, sorry for the delay here; animation controllers should support .reset() now. Check it out here: https://pub.dev/documentation/rive/latest/rive/SimpleAnimation/reset.html

zplata avatar Jan 25 '22 02:01 zplata

Hi. did you fix it now. I did use Reset in the past but it did nothing. So I was forced to make another animation that would reset the values and call that after I call the reset.

JacoFourie avatar Jan 26 '22 05:01 JacoFourie

The .reset() method does not work for me either 😕

Flutter version: 2.8.1 Rive Version: 0.8.1

Use case: Using two SimpleAnimation controllers in a StatefulWidget and toggling between them.

simonifergan avatar Feb 04 '22 23:02 simonifergan

Hi @zplata . The reset does nothing. How should it be used?

JacoFourie avatar Feb 05 '22 20:02 JacoFourie

Getting same problems here

TheFe91 avatar Feb 23 '22 16:02 TheFe91

@zplata Is anybody at Rive looking at these errors?

JacoFourie avatar Mar 26 '22 22:03 JacoFourie

Hey @JacoFourie, sorry I missed your original tag. I'll try and find some time to repro this with a looping animation and see what's going on (I think I tested with a OneShot before). We definitely keep an eye on the issues of our runtimes and try to balance our resources on these.

zplata avatar Mar 28 '22 15:03 zplata

@JacoFourie Wondering if you have any code snippets to share on how you're calling reset?

Calling .reset() on its own from a SimpleAnimation controller should reset the animation to its starting time frame. On its own, it won't stop the animation; you need to toggle the isActive property on the controller, and just these 2 lines alone won't bring the animation to "frame 0".

To achieve the effect of stopping an animation and getting it to the first frame on a reset, try the following:

_controller.reset();
_controller.apply(_artboard as RuntimeArtboard, 0);
_controller.isActive = !_controller.isActive;

Check out this gist example: https://gist.github.com/zplata/44548006ab4f70e7802ba0035d9f3dce - hopefully this helps!

zplata avatar Mar 30 '22 00:03 zplata

@zplata I stop the animation by setting it to false and the issue the reset command. The animation will only reset on the screen when you start it again. I need it to go back to the first frame on the screen when I reset it. OK I will try your method. Thanks.

JacoFourie avatar Mar 31 '22 13:03 JacoFourie

I made used of drawFrame() and reset() that two commands worked for me

Eduardo-Mercado avatar Nov 22 '22 16:11 Eduardo-Mercado

Another option would be to make use of reset and to only pause the animation on the next Flutter frame.

controller.reset();
WidgetsBinding.instance.addPostFrameCallback((_) {
  controller.isActive = !controller.isActive;
});

However, what @zplata suggested also works, and may be the better approach.

Closing this for now. If anyone stumbles on this and have suggestions/issues feel free to re-open.

HayesGordon avatar Feb 21 '23 10:02 HayesGordon

Hi, guys! Still running into this issue. How can I use the reset method if I'm using a RiveAnimationController?

cc: @zplata

RiveAnimationController? _controller;

@override
void initState() {
  super.initState();
  _controller = OneShotAnimation(
    widget.animationName,
    autoplay: false,
  );
}
RiveAnimation.asset(
  widget.animationAsset,
  controllers: [_controller!],
  animations: [widget.animationName],
),

eRuaro avatar Apr 28 '23 03:04 eRuaro