Flex Web 应用程序:防止窗口不可见时帧率下降

发布于 2024-12-17 09:31:46 字数 406 浏览 1 评论 0 原文

因此,自 10.1 版本以来,Flash 播放器中出现了一项新“功能”,当应用程序窗口不在视图中时,该功能会将播放器的帧速率降低至 2 fps。这对于性能来说是个好消息,但它可能会破坏某些功能,例如 Timer 类。

我有一个使用计时器来显示倒计时的应用程序。鉴于应用程序的性质,即使用户不在场,计时器也需要完成倒计时。想象一下,您只需要给用户 10 秒的时间来执行任务。如果用户在计数器中途最小化窗口,他们可以想花多少时间就花多少时间,并且当他们返回窗口时仍有 5 秒的时间。对于较新的 Flash 播放器来说,这显然是无法避免的。

在Air应用程序中,可以设置backgroundFrameRate属性来防止这种行为,但这是WindowedApplication类的一部分,因此它似乎在Web应用程序中不可用。有谁知道即使窗口不可见也能保持恒定帧速率的方法?谢谢

So there's been a new "feature" in the flash player since version 10.1, which reduces the player's framerate to 2 fps when the application window is out of view. This is good news for performance, but it can break some functionality, such as the Timer class.

I have an application which uses a Timer to display a countdown. Given the nature of the application, it is required for the Timer to complete its countdown even if the user is not there to see it. Imagine that you need to give the user only 10 seconds to perform a task. If the user minimizes the window halfway through the counter, they can take as much time as they want and still have 5 seconds left when they return to the window. This apparently can not be avoided with the newer flash players.

In Air applications there is the backgroundFrameRate property which can be set to prevent this behavior, but this is part of the WindowedApplication class, so it seems that it is not available in a web application. Does anyone know a way to keep a constant frame rate even when the window is not visible? Thanks

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

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

发布评论

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

评论(3

猫卆 2024-12-24 09:31:46

将嵌入的 swf 的 wmode 参数设置为不透明将防止帧速率限制。

布莱恩

Setting the wmode parameter of the embedded swf to opaque will prevent the framerate throttling.

Brian

心的憧憬 2024-12-24 09:31:46

我自己没有尝试过,但也许您可以尝试强制关闭帧速率:

stage.addEventListener(Event.DEACTIVATE, onDeactivate); 

function onDeactivate (e:Event):void 
{ 
    //eg myFrameRate=24
    stage.frameRate = myFrameRate; 
} 

让我知道这是否有效。

I've not tried myself, but maybe you can try to force the framerate onDeactivate:

stage.addEventListener(Event.DEACTIVATE, onDeactivate); 

function onDeactivate (e:Event):void 
{ 
    //eg myFrameRate=24
    stage.frameRate = myFrameRate; 
} 

Let me know if this works.

泪痕残 2024-12-24 09:31:46

测试:

private var numer:int = 0;
private var prevNumer:int = 0;
private var timer:Timer = new Timer( 1000, 0 )

[...]

var tf:TextField = new TextField ();
addChild (tf);
addEventListener ( Event.ENTER_FRAME, onEnterFrame )
timer.addEventListener (TimerEvent.TIMER, onTimer )
timer.start()
function onTimer ( e:TimerEvent ):void
{ tf.appendText (' ' + (numer - prevNumer)); prevNumer = numer;}
function onEnterFrame ( e:Event ):void { numer++ }

清楚地表明,当您看到闪光时,tf 会附加等于您的 FPS 的数字。如果计时器与 FPS 一起更改,则最小化窗口时您不会看到差异。但是,回来后您会看到 2 2 2 2 2,即 FPS 下降到 2。AsTheWormTurns

的 onDeactivate 解决方案不起作用。事件已触发,但 fps 未更改。
Brian Bishop 先生的 wmode=opaque 解决方案不起作用,太

明显了,无法尝试:更改 onEnterFrame 函数来设置 FPS:

function onEnterFrame ( e:Event ):void { numer++; stage.frameRate = 30 }

显然,当闪光灯不可见时,您无法设置 FPS!好吧,除非将其设置为 1,否则您无法设置 FPS。

解决问题的方法很简单,只需制作另一个与上面类似的计时器,但带有附加条件:

function onTimer ( e:TimerEvent ):void {
if ( numer - prevNumer == 2 ) adjustOriginalTimer();
tf.appendText (' ' + (numer - prevNumer)); prevNumer = numer;
}

E:您可以在此处阅读相关内容:http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-8000.html

Testing with:

private var numer:int = 0;
private var prevNumer:int = 0;
private var timer:Timer = new Timer( 1000, 0 )

[...]

var tf:TextField = new TextField ();
addChild (tf);
addEventListener ( Event.ENTER_FRAME, onEnterFrame )
timer.addEventListener (TimerEvent.TIMER, onTimer )
timer.start()
function onTimer ( e:TimerEvent ):void
{ tf.appendText (' ' + (numer - prevNumer)); prevNumer = numer;}
function onEnterFrame ( e:Event ):void { numer++ }

shows clearly, that when You see the flash, tf appends numbers equal to Your FPS. If timer would get changed together with FPS, You wouldn't see a difference when minimizing a window. But, coming back You see 2 2 2 2 2, that is, FPS dropped to 2.

onDeactivate solution by AsTheWormTurns doesn't work. Event is fired, but fps not changed.
wmode=opaque solution by Mr Brian Bishop doesn't work too

something obvious to try: change onEnterFrame function to set FPS:

function onEnterFrame ( e:Event ):void { numer++; stage.frameRate = 30 }

Obviously You can't set FPS when flash is not visible! Well, You can't set FPS unless You set it to 1.

Workaround to Your problem is simple, just make another timer similar to this above but with additional conditional:

function onTimer ( e:TimerEvent ):void {
if ( numer - prevNumer == 2 ) adjustOriginalTimer();
tf.appendText (' ' + (numer - prevNumer)); prevNumer = numer;
}

E: You can read about it here: http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-8000.html

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