如何避免 flash.display 闪烁

发布于 2024-11-05 07:39:03 字数 675 浏览 0 评论 0原文

来自更“传统”的 C++ 背景,因此更习惯于处理低级 API,而不是 flash.display API 之类的东西。

我的问题相当初级,但我的搜索尚未找到解决方案。

如何避免显示 API 中的屏幕撕裂/闪烁? 即使使用 60 fps 等高帧率,我也会在帧之间遇到一些相当令人讨厌的闪烁/撕裂。

以下面的简单示例为例,其中 Sprite 的子级只是 Shape 的实例,并且永远不会改变。

private function onEnterFrame(event:Event):void
{   
    var t:Number = (getTimer() - time) / 1000;
    time = getTimer();

    step(t);
}

private function step(t:Number):void {
    var speed:Number = 100;

    for (var i:uint = 0; i < numChildren; i++){             
        getChildAt(i).x += speed * t;
        getChildAt(i).y += speed * t;
    }
}

然而,由于其他人都能够制作看似流畅的快速动画,我对实际如何做到这一点感到有点困惑,因为它基本上看起来像是一个同步问题。

Coming from a more 'traditional' C++ background so more used to dealing with low level API's rather than something like the flash.display API.

My issue is rather rudimentary, but my searches haven't found a solution.

How does one avoid screen tearing/flickering in the display API?
Even with a high framerate like 60 fps I'm experiencing some rather nasty flickering/tearing between frames.

Take the simplistic example below, where the children of the Sprite are merely instances of Shape and never change.

private function onEnterFrame(event:Event):void
{   
    var t:Number = (getTimer() - time) / 1000;
    time = getTimer();

    step(t);
}

private function step(t:Number):void {
    var speed:Number = 100;

    for (var i:uint = 0; i < numChildren; i++){             
        getChildAt(i).x += speed * t;
        getChildAt(i).y += speed * t;
    }
}

However, since everyone else is able to do seemingly smooth fast animations I'm sort of puzzled as to how actually do it since it basically seems like a sync issue.

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

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

发布评论

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

评论(2

陪我终i 2024-11-12 07:39:03

首先:你让你的CPU比必要的更努力地工作,25/30 fps应该可以实现平滑的动画,所以你只能以这个速率调用step。在更新 x、y 的精灵外观位置之前,仅当它们已更改时才真正更改和更新。

让循环尽可能紧密:将 numChildren (方法调用)从循环中取出。将速度变量设置为 int 而不是 Number(更快)

看看精灵:它们有透明度吗?透明度是性能杀手,因为闪存必须在每一帧上绘制所有图层。我可以进一步优化它们,例如,在不损失质量的情况下使它们尽可能小(如果您使用的是缩小到精灵大小的更大图像)。

First: you are letting your CPU work harder than necessary, 25/30 fps should do for a smooth animation, so you can call step only at this rate. Before updating location of the sprites look of x, y really change and update only if they have changed.

Make your loop as tight as you can: take numChildren (method call) out of the loop. Make speed variable an int instead of Number (faster)

Look at the sprites: do they have transparency? Transparency is a performance killer, since flash has to draw all layers on each frame. Optimize them further I you can, for example make them as small as you can without loosing quality (in case you are using bigger images that get scaled down to the sprite size).

甩你一脸翔 2024-11-12 07:39:03

我发现 wmode 参数对动画平滑度有很大影响。相同的 swf 在独立播放器和具有不同 wmode 的 html 页面上的行为有所不同。经过一些测试,我更喜欢 wmode="direct" - 它提供最平滑的运动,甚至比“gpu”更好。

使用一些 ActionScript 监控工具(例如 Stats)来查看真实的 fps 是件好事。如果它保持在高位并且您仍然看到不稳定的运动,则这是 wmode 问题。而且 60 fps 比 30 fps 更好,如果您不受性能限制,为什么不使用它。

I've seen wmode parameter having large influence on animation smoothness. The same swf behaves differently in standalone player and on html page with different wmodes. After some tests, I'm preferring wmode="direct" - it gives smoothest movements, even better than "gpu".

It's good to see your real fps with some monitoring tool for ActionScript, for example, Stats. If it stays high and you still see jerky movements, it is wmode issue. And 60 fps are better than 30, if you're not performance bound, why not use it.

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