Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I reset an animation to the beginning? #165

Closed
JacoFourie opened this issue Aug 28, 2021 · 14 comments
Closed

How do I reset an animation to the beginning? #165

JacoFourie opened this issue Aug 28, 2021 · 14 comments
Labels
bug Something isn't working

Comments

@JacoFourie
Copy link

JacoFourie commented Aug 28, 2021

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 JacoFourie added the bug Something isn't working label Aug 28, 2021
@JacoFourie
Copy link
Author

Is there a way??

@zplata
Copy link
Contributor

zplata commented Jan 25, 2022

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

@JacoFourie
Copy link
Author

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.

@simonifergan
Copy link

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.

@JacoFourie
Copy link
Author

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

@TheFe91
Copy link

TheFe91 commented Feb 23, 2022

Getting same problems here

@JacoFourie
Copy link
Author

JacoFourie commented Mar 26, 2022

@zplata Is anybody at Rive looking at these errors?

@zplata
Copy link
Contributor

zplata commented Mar 28, 2022

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
Copy link
Contributor

zplata commented Mar 30, 2022

@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!

@JacoFourie
Copy link
Author

JacoFourie commented Mar 31, 2022

@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.

RezaHaidari added a commit to RezaHaidari/rive-flutter that referenced this issue Jul 19, 2022
@Eduardo-Mercado
Copy link

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

@HayesGordon
Copy link
Contributor

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.

@eRuaro
Copy link

eRuaro commented Apr 28, 2023

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],
),

@martinfrouin
Copy link

Same question as @eRuaro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants