让系统时间决定动画速度,而不是编程 FPS

发布于 2024-08-26 11:44:15 字数 337 浏览 7 评论 0原文

我正在使用 ActionScript 3 编写纸牌游戏。每张纸牌都由一个类的实例表示,该类扩展了从 Flash CS4 导出的影片剪辑,其中包含纸牌图形和翻转动画。当我想要翻转卡片时,我会在此影片剪辑上调用 gotoAndPlay。

当帧速率减慢时,所有动画都需要更长的时间才能完成。默认情况下,Flash 似乎会以确保绘制剪辑中所有帧的方式对影片剪辑进行动画处理。因此,当节目帧速率低于剪辑的帧速率时,动画将以较慢的速度播放。

我希望动画始终以相同的速度播放,因此始终在屏幕上显示相同的时间。如果帧速率太慢而无法显示所有帧,则会丢失帧。可以用这种方式告诉 Flash 制作动画吗?如果没有,我自己编写此行为的最简单方法是什么?

I'm writing a card game in ActionScript 3. Each card is represented by an instance of a class extending movieclip exported from Flash CS4 that contains the card graphics and a flip animation. When I want to flip a card I call gotoAndPlay on this movieclip.

When the frame rate slows down all animations take longer to finish. It seems Flash will by default animate movieclips in a way that makes sure all frames in the clip will be drawn. Therefor, when the program frame rate goes below the frame rate of the clip, the animation will be played at a slower pace.

I would like to have an animation always play at the same speed and as a consequence always be shown on the screen for the same amount of time. If the frame rate is too slow to show all frames, frames are dropped. Is is possible to tell Flash to animate in this way? If not, what is the easiest way to program this behavior myself?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

那些过往 2024-09-02 11:44:15

最简单的方法是使用 Timer (或 setInterval)每 1000/fps 毫秒触发一次,告诉您的 MovieClip 转到下一个框架。

如果您需要更准确的信息,则必须检查自上次更新以来所花费的时间(从 这篇文章来自 Keith Peters 的博客,它很好地解释了所有内容)。

The easiest way would be to use a Timer (or a setInterval) triggering every 1000/fps milliseconds, telling your MovieClip to go to its next frame.

If you need something more accurate, you'll have to check the time spent since the last update (stolen from the first comment of this article from Keith Peters' blog, which explains everything pretty well).

陪我终i 2024-09-02 11:44:15

自从我使用 Flash 以来已经有一段时间了,但据我了解,这是不可能的,因为 Flash 使用基于帧的动画模型。

然而,Silverlight 使用基于时间的动画模型,并且只会在帧速率允许的情况下绘制尽可能多的中间帧。

It's been a while since I used Flash but from what I understand it's not possible because Flash uses a frame based animation model.

Silverlight however uses a time based animation model and will just draw as many intermediate frames as the frame-rate allows.

一张白纸 2024-09-02 11:44:15

补间类 (fl.transitions.Tween) 非常适合这种情况。通过将构造函数的最后一个参数设置为 TRUE,然后它的动画/触发以秒为基础,据我所知,它可以补偿 FPS 损失/增益。

您可以像 Timer 类一样轻松地使用它,方法是将新对象 (Trigger(new Object(), "x")) 传递给构造函数并为 MOTION_FINISH 创建侦听器 (TweenEvent.MOTION_FINISH< /code>) 来触发你的事件!

我使用 Tweens 来做很多事情,因为它们简单、快速并且受到所有支持,而且正如我所说,它应该可以解决你的 FPS/延迟问题,因为它可以适应 FPS 的变化。实时(据我所知!)。

The tween class (fl.transitions.Tween) is perfect for this situation. By setting the last argument of the constructor to TRUE then it bases its animations/triggers off of seconds, and as far as I know it compensates for FPS loss/gain.

You can easily use it like the Timer class by passing a new object (Trigger(new Object(), "x") to the constructor and creating a listener for MOTION_FINISH (TweenEvent.MOTION_FINISH) to trigger your event!

I use Tweens for a LOT of things because they're easy, fast, and supported by everything. And like I said, it should solve your FPS/lag issues since it adjusts to FPS changes in real-time (as far as I know!).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文