unity-rlottie icon indicating copy to clipboard operation
unity-rlottie copied to clipboard

Stopping on the last frame when the animation ends.

Open ivanmazur62 opened this issue 2 years ago • 3 comments

It would be great to add the ability to stop the animation on the last frame if the loop is set to false. Currently, the Stop method is being called there, and this method resets the frame to 0.

ivanmazur62 avatar Aug 02 '23 10:08 ivanmazur62

Hello @ivanmazur62, thanks for a nice suggestion! I can add an additional parameter to the Animated Image / Button "stopAtTheLastFrame" which will be false by default. So that if you need this setting, you need to enable it explicitly. What do you think?

gindemit avatar Aug 03 '23 07:08 gindemit

Yes, this is a great solution. There's also another issue, on devices it sometimes skips the last frames for some reason, and then the animation stop doesn't trigger, and it goes in a loop. I added the transfer of the Loop parameter from the AnimatedImage class to the LottieAnimation class and handle the stop there.

ivanmazur62 avatar Aug 04 '23 07:08 ivanmazur62

Thank you for additional report. I understand why it can happen when the non loop animation does not stop. It can happen that the device delta time between frames is sometimes bigger that the animation time delta and the animation skips one or more frames. I'll handle this case with more care. Thank you! But there is a hard (==) check to stop the animation when loop is false:

if (!_loop && _lottieAnimation.CurrentFrame == _lottieAnimation.TotalFramesCount - 1)

image

gindemit avatar Aug 04 '23 09:08 gindemit