Understanding frames in animations
What is the meaning and usage of frames in animations? I do understand that they are related with animation smoothness. The开发者_如何学Python more frames per second are shown the more animation is smooth. What is the theory and usage guide when building apps with animations (for example games)? Currently, I distinct two types of 2D animations:
a) frame based animations. IMHO frame based animations are just repositioning the views on screen with timers with some settings to do that movement smooth.
b) motion tween based animations. IMHO, that are the ones that involve the usage of UIView animateWithDuration and other similar methods.
Currently, I'm using CADisplayLink as a timer for my app. The timer is initialized with frameInterval = 2. The calls some method that repositions some views on screen using 1 point values. I consider that movement type as frame-based animation and it is more or less smooth. What I don't understand clearly what happens beneath that, what is my framerate and etc? Does using CADisplayLink somehow adds some intermediate values (frames) when moving (animating) from x=12 to x=13?
I'm also using some UIView animateWithDuration, so I consider that as motion tween animation. I see that the framerate settings are assured for me, I do not need to do anything about framerate explicitly, right?
Yes, when you use the standard animation calls, like animateWithDuration, your code doesn't have to worry about frame rates. There is a possibility that the animation might not run as fast as you'd like or be as smooth as you like, if there are too many non-opaque objects being drawn on top of each other or if you're keeping the the CPU/GPU busy in =some other way. In that case you would have to simplify the objects (making them opaque for example) or do your own animation, possibly resorting to OpenGL.
As for the other question about frame rates, it basically boils down to how many times can you draw the changes you need for each step in the animation, in a second. You may only need to do the drawing 15 times to make the animation look smooth, depending on the amount of movement. Once you know what optimal number of FPS you are trying to achieve, then you would time your drawing code to see if you can accomplish what you need in the time needed. Actually, before you start timing anything, try doing the drawing at the time interval that gives you the FPS you need, and see how it looks. You may not need to worry about timing it if you are getting the animation you want.
精彩评论