rive-flutter
rive-flutter copied to clipboard
How do I reset an animation to the beginning?
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.
Is there a way??
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
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.
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.
Hi @zplata . The reset does nothing. How should it be used?
Getting same problems here
@zplata Is anybody at Rive looking at these errors?
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.
@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 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.
I made used of drawFrame() and reset() that two commands worked for me
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.
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],
),