How to control a Flutter/Flare animation based on timer? - flutter

I want to accomplish the following:
Based on a variable timer (hours, minutes and seconds) three goals have to be fulfilled: Received, Preparing and Ready.
Example: when the timer is about 15 seconds, the lines and the dot have to be filled with the orange color -- just in a linear way.
So far, I have accomplished this:
Where:
The first line is made with Flutter CustomPainter
The second line is made with Flare, see:https://www.2dimensions.com/a/JohanWalhout/files/flare/fill-line/embed
Now, I'm facing the follow problems:
How can I animate the Flutter CustomPainter like the Flare animation?
or:
How can I animate the Flare animation where the animation duration is the time it takes to fill the orange color?
Please, see the complete app in the following repo: https://github.com/LiveLikeCounter/Flutter-Food-Delivery

Flare and CustomPainter are two completely different things. CustomPainter is a widget that comes with the Flutter SDK and Flare is an vector animation tool by 2Dimensions. They cannot change/manipulate each other in any way.
How can I animate the Flare animation where the animation duration is
the time it takes to fill the orange color?
If you want to stick to Flare then you can separately create the fill animation and use FlareController to play the animation as and when you wish.
Just remember the name you give it e.g In this case, it is 'home-on' and 'home-off'
Refer to this blog before you start to code/design:
https://medium.com/2dimensions/building-a-responsive-house-with-flare-flutter-31af823ba805
However, it is still recommended that you use AnimationController and some variables to get full control of your widgets instead of relying on any third party animation tool.

For the custom painter you can use a basic canvas.drawLine and make sure your shouldRepaint returns true when ever the end line position changed. The end position will be relative to the timer and what you consider a line to be full.
For the Flare animation you have to create a controller that will take in the time on every timer tick you want to animate, then set your current playback time for you artboard equal to the position you want for that time. 15second = 100% in your case so your applied time should be the full animationDuration, 7.5 you'll set it to animationDuration * 0.5, so you have to figure your formula out for that.
You can use my SwipeAdvanceController from SmartFlare then call updateSwipePosition using Fake values that will represent your "swipe". The controller will advance from 0 to 100% of the animation depending on how you swipe over the animation allowing you to create sliders, etc using Flare so it should work with this by passing in fake touch positions to emulate.

Related

Gradually decreasing the velocity of an object through animation in Unity

I need to create 2 animations,
one is of an object going from point A to point B at a constant velocity.
the other is of an object starting from point A but with a gradually decreasing velocity as it reaches point B until it comes to a stop.
I tried decreasing the animation speed every second to achieve this result with no luck.
Any ideas?
As you may have noticed when you work with animation in Unity there is no such thing as changing the velocity of an object. What you need to do is give your object an Animator and create a new Animation.
Then on the animation timeline press the red dot (record button) and then place your object on point A.
Next, on the time line you want to select the exact second that you want your object to come to a stop and after that move the object on point B.
Now, the more seconds there are in between the 2 keys, the more time it's going to take for the object to travel.
To make it gradually slower instead of it just travelling slowly:
On the animation panel you will see 2 tabs. Dopesheet and Curves. Hit Curves and play around with them till you have a satisfing result.
Documentation on using Curves

Flare/Flutter: How to reset the progress of an animation before starting it?

I have a Flare file with 3 animations contained within it, all in the same artboard. I understand that when switching between animations, Flare will mix the animations together by default, and that playing one animation will not reset the relevant nodes values back to what they were on frame 0 in the editor. That is the behavior I would like to achieve: when playing a new animation, I would like the previous animation to stop completely (don't mix them at all) and for the incoming animation to start at the very beginning with all its default values.
The use case is this:
Play an animation where, say, the opacity of a shape goes down to zero
Play a different animation that uses the shape from above, but in the Flare editor its opacity is 1 at the start of the animation
Desired result: the new animation resets the opacity of the shape and then begins and plays like normal
Actual result: since the previous animation changed the shape's opacity, the new animation will use the shape how it is instead of how it was created in the editor
For my question as explained on GitHub you can look at the end of the thread on this issue (has gifs): https://github.com/2d-inc/Flare-Flutter/issues/14
In the above thread, Luigi Rosso mentions "re-instancing" the artboard. Does anyone know what he means by this and how to do it? I have tried several methods of doing this such as the makeInstance methods found on classes such as FlutterActorArtboard, ActorNode and some others (there are a few variants of the makeInstance method but they are all similarly named and return a new artboard. However, I had no luck with replacing the current instance of my artboard in a FlareController implementation so far.
I have also tried to manually loop through all of the ActorNodes of the artboard and first saving their initial values and then copying the saved values to the artboard every time a new animation is played, but this seemed to break things pretty badly (the animation was unrecognizable and just didn't play correctly after that, so I must have done something wrong. Or I'm resetting the wrong values).
Any help is appreciated, thanks!
For playing a different animation on a shape and resetting its opacity, you can access the opacity of the node at runtime with:
ActorNode myNode = _artboard.getNode("nodeString");
myNode.opacity = 0.00;
As outlined here in the manual.
More simply, in the new animation, you can set a keyframe in the Rive/Flare editor for the opacity to be 1 at the start of the new animation, so that when it plays the animation from the beginning its opacity will be reset to 1.
For playing one animation, then overriding it completely when the next animation plays you can extend the FlareController and create a custom animation controller to do this in the advance method.
Here's a quick and dirty example (not best practices) to give you an idea of using advance:
https://gist.github.com/she-who-codes/85d8f0da97abfc3ecc43b1cb470e9c29
https://gist.github.com/she-who-codes/ce633204cd2d4babfe9a5b54e34ca63d

Unity - Animation Loops?

I am using an FBX 3D object file as a game object in my project which have further sub assemblies. Now i want to animate a part of the assembly.
I followed this process:
Select the part which I want to animate.
In the animation panel create one animation.
Add property > transform > position
Using pivot, i move that part to the location where I want to animate.
Challenges
Animate in loop. Moreover if I Select animation file, it does not show Wrap mode
( 1. I don't want any loops in my animation, even after deselecting loop-time it does loop. - I dont know why?
It is animating in reverse. suppose if the object needs to go from position x:3 to position x:8 but it goes from position x:8 to position x:3
the above point happens in loop. just like a ping pong)
Animates in reverse.
I take the whole animation as one loop i.e Part comes out of assembly and goes back and repeating for infinite time.
I want to stop the animation till the point it comes out.
Any help will be appreciated

How to apply timer based throb or pulse or fade-away effects to an image in IPhone or iOS?

This is a multi-part question:
How can one create an animation-block and hook it up with a timer such that the animation block runs when the image is put on display in the iPhone?
How can any one of the following three effects be applied to an image?
throb effect
pulse effect (same thing as throb as far as I can guess)
fade-away or fade-out effect
Apply the size or alpha transforms to your image within the animation block, and then create a callback function (called after the animation is complete) that calls a function that applies the opposite animated transform to your image. Then the callback for that function will start the cycle again, and so on.

small delays/pause in animation

Hi all can anyone help me out with the solution to this problem...
I have a project where I have NSTimer fire about 20 times a sec and thus using only one image(loaded programatically)produces the same image on the iPhone screen about twenty times in a second and these images fall from the top of the screen to the bottom where they are removed(more or less simulating rain fall or rain droplets).
My problem is that looking at the animation, I noticed that there are very small delays and which looks like a break, pause or small vibrations. Thus the flow isn't smooth.
Can anyone help me with the solution please.
Thanks in advance
You can check the CADisplayLink class.
Just because you ask for a timer in the UI run loop to go off at a certain rate, doesn't mean you will get called at exactly that rate or at evenly spaced intervals. You should check the time and the elapsed time "dt" inside each timer callback, and change your animation position, y + dy * dt, etc., accordingly.
Timer's arn't designed to be used for animation.
The best thing to do, is to have a thread running in an infinite loop, where you check if it's time to animate again, or just always animate (giving you a higher frame rate), but using the time elapsed as a reference for the state you are drawing.
You really shouldn't be using a timer for this. Instead you should be using the built in UIView animation methods:
animateWithDuration:animations:
animateWithDuration:animations:completion:
animateWithDuration:delay:options:animations:completion: