The documentation is very poor on this. What's the effect of these? The only thing that seems to work as expected is kCAAnimationLinear. What can I do with the others, for example?
kCAAnimationDiscrete
Each keyframe value is used in turn, no interpolated values are calculated.
This just means that there is no animation at all. And whatever keyframe values that you provide when setting up a keyframe animation will be used like a straight slide show with no transitions.
kCAAnimationPaced
Keyframe values are interpolated to produce an even pace throughout the animation.
This applies a timing curve to your animation from one keyframe to another, producing a slight cadence to the animation. Similar in effect to the CAMediaTimingFunction kCAMediaTimingFunctionEaseInEaseOut.
The calculationMode property is applied to all keyframe transitions within the entire animation.
Individual timing functions can be specified for each keyframe transition by providing an NSArray of CAMediaTimingFunction instances and passing it to the timingFunctions property of the animation. The array of timing functions must match the array of keyframes in number for it to work.
Related
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
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
I am learning a different way to create a custom indicator. Below is a partial code from tutorial using CABasicAnimation to achieve a task.
-(void)spin
{
CABasicAnimation *spinAnimation = [CABasicAnimation animationWithKeyPath:#"transform.rotation"];
spinAnimation.toValue = [NSNumber numberWithFloat:2*M_PI];
spinAnimation.duration = self.animationDuration;
spinAnimation.delegate = self;
[self.layer addAnimation:spinAnimation forKey:#"spinAnimation"];
}
What is the toValue at line number 2 and what it is used for. When I tried to use
spinAnimation.byValue = [NSNumber numberWithFloat:2*M_PI];
I dont get the idea of these interpolation values.Was searching over the internet but cant still get the whole picture of it..
Please help if you have any ideas about it. All comments are appreciated.
CABasicAnimations can be a little tough to wrap your head around, but the properties associated with the animation really aren't that tough, once you can visualize what they're trying to accomplish. For instance, if I have a red square that represents a layer, and I want to rotate it 360˚ (as you're doing there), then I have to initialize an animation object, tell it what I want to animate, and where I want the animation to go.
The animation you've provided mutates a CALayer's internal matrix so that it is rotated to a given value (in this case, 2 * M_PI, or 360˚) from it's current position (because you haven't specified a fromValue) over the given duration. A given by value tells the animation that over the given period of time, you want the animation to interpolate (or move) by the given value for the provided duration (for instance, you could chunk the animation into 45˚ "blocks" by specifying a byValue of #(M_PI/2)). The default byValue is a division of the difference of the toValue and fromValue over the duration of the animation such that the animation is smooth and continuous.
So, you can think about the animation as going from the layer's initial rotational value, to the layer's new rotational value, by interpolating a given amount or value for a period of time.
You can comprehend "byValue" its means plus the value in original.
I have four positions in my CAKeyframeAnimation that are part of a bezier path and my animation is working great along the path.
But now I need the animated sprite to be moved to one specific value of the keyframe position values. how could I realize that?
thnx!
Pull the relevant values out of the CAKeyframeAnimation's keyTimes, values, and potentially timingFunctions arrays, then create a CABasicAnimation out of those.
I want to create an animation that interpolates some property for 2 seconds and only 20 frames (presentation layers) have to be generated by the CoreAnimation framework. I know how to provide a duration for the explicit animation but which property do I have to change in order to get particular number of frames calculated by interpolation process?
Thanks in advance.
Core Animation works by using interpolation--calculating intermediate values in between key values you specify. If it's a keyframe animation, it interpolates between the number (n) of values in your values array. If it's a basic animation, it interpolates between two values--your start and end values. If you just want to change the frame rate of the animation instance go through this How to change the frame rate of a core animation instance?
What you want is not possible with Core Animation. The number of times it draws your layer is based off your program's frame rate.