使用 ActionScript 3 停止在 Flash 中渲染
这是我的问题:我有一些通过循环修改的显示对象,并且我希望 Flash 在每个循环结束时准确渲染一帧。循环的持续时间可能会发生不可预测的变化,因此恒定的帧速率无法做到这一点。
我找到了一种在每个循环结束时渲染一帧的黑客方式,使用 updateAfterEvent 和 0ms 计时器。现在我想阻止 Flash 在循环中间渲染帧:这会浪费时间和资源,并且会产生奇怪的闪烁效果。将帧速率设置为 0 将是一个简单的解决方案,但 stage.frameRate 的最小值为 0.01。
问题1:有没有办法正确停止标准渲染循环? 解决方法不会被视为有效答案,因为我当前正在做的是一个非常好的解决方法(每 100 秒 1 帧是可以忍受的)。
问题2:有没有比updateAfterEvent更好的方法来强制渲染?
哎呀,我忘记了礼貌。早上好/下午好,谢谢。
Here's my problem: I have a few display objects that are modified by a loop, and I would like flash to render exactly one frame at the end of each loop. Duration of a loop may vary unpredictably, thus a constant frame-rate won't do it.
I found a hack-ish way to render one frame at the end of each loop, using updateAfterEvent with a 0ms timer. Now I want to prevent Flash from rendering frames in the middle of the loop: this is a waste of time and ressources, and produces strange blinking effects. Setting the frame rate to 0 would be an easy solution, but stage.frameRate has a minimum value of 0.01.
Question 1: Is there a way to properly stop the standard rendering loop?
A workaround will not be regarded as a valid answer, because what I'm currently doing is a pretty good workaround (1 frame every 100 seconds is bearable).
Question 2: Is there a better way than updateAfterEvent to force rendering?
Oops, I forgot civilities. Good morning/afternoon, please, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 updateAfterEvent 强制在下一个计划的渲染更新之前进行渲染并没有什么问题,但是浪费的计时器是不可取的(函数调用太多)。相反,在循环结束时分派您自己的渲染事件,侦听它,然后更新 AfterEvent()。
也就是说,如果我们讨论的是 for、while 等循环,那么您不应该看到在循环中间渲染的内容。 Flash 在同步代码执行期间不会呈现。这部分让我想知道你的代码中到底发生了什么。
There's nothing wrong with using updateAfterEvent to force rendering ahead of the next scheduled render update, but your wasteful timer is undesirable (too many function calls). Instead, dispatch your own render event at the end of the loop, listen for it, and updateAfterEvent() then.
That said, you should not see things rendering in the middle of a loop, if what we're talking about is a for, while, etc.. loop. Flash doesn't render during synchronous code execution. That part has me wondering what's really going on in your code.
有不同的方法可以解决这个问题,尽管这似乎是您的整体设计问题,而不是 Flash 中的限制。我认为长时间循环往往是一个坏主意......如果您需要完全控制,我会在屏幕外渲染所有内容,而不是将当前对象附加到 DisplayList。这需要将所有内容添加到未附加的精灵中,然后在需要时绘制它。这里的缺点是你不会得到任何鼠标事件/键盘事件。
看起来像:
There are different ways to go about this, though this seems like a problem with your design overall rather than limitations within Flash. I think a long while loop tends to be a bad idea .... If you need full control I would offscreen render everything rather than attach your current objects to the DisplayList. This requires addChild'ing everything to a non-attached sprite, then drawing it when you want. The drawback here is that you won't get any mouseevent/keyboardevent.
Looks like: