了解动画中的帧
动画中帧的含义和用途是什么?我确实明白它们与动画流畅度有关。每秒显示的帧数越多,动画就越流畅。构建带有动画的应用程序(例如游戏)时的理论和使用指南是什么?目前,我区分两种类型的 2D 动画:
a) 基于帧的动画。恕我直言,基于帧的动画只是使用计时器重新定位屏幕上的视图,并进行一些设置以使移动平滑。
b) 基于补间动画的动画。恕我直言,这些涉及使用 UIView animateWithDuration 和其他类似方法。
目前,我使用 CADisplayLink 作为我的应用程序的计时器。计时器使用frameInterval = 2 进行初始化。调用一些方法,使用1 点值在屏幕上重新定位某些视图。我认为这种运动类型是基于帧的动画,它或多或少是平滑的。我不清楚下面发生了什么,我的帧速率是多少等等?当从 x=12 移动(动画)到 x=13 时,使用 CADisplayLink 是否会以某种方式添加一些中间值(帧)?
我还使用了一些 UIView animateWithDuration,所以我认为这是补间动画。我看到帧速率设置对我来说是有保证的,我不需要明确地对帧速率做任何事情,对吗?
What is the meaning and usage of frames in animations? I do understand that they are related with animation smoothness. The 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,当您使用标准动画调用(例如 animateWithDuration)时,您的代码不必担心帧速率。如果有太多非不透明对象相互重叠绘制或者您保持 CPU 占用,则动画可能无法按照您希望的速度运行得那么快,也可能无法像您希望的那样流畅/GPU 以其他方式忙碌。在这种情况下,您必须简化对象(例如使它们不透明)或制作自己的动画,可能需要借助 OpenGL。
至于关于帧速率的另一个问题,它基本上可以归结为在一秒钟内您可以为动画中的每个步骤绘制多少次所需的更改。您可能只需要绘制 15 次即可使动画看起来平滑,具体取决于移动量。一旦您知道想要达到的最佳 FPS 数量,您就可以对绘图代码进行计时,看看是否可以在所需的时间内完成所需的任务。实际上,在开始计时之前,请尝试按照能够提供所需 FPS 的时间间隔进行绘图,然后看看效果如何。如果您获得了想要的动画,您可能不需要担心计时问题。
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.