定时器事件被堵塞,在AS3触发一次全部 [英] Timer events are clogged and triggered all at once in AS3

查看:144
本文介绍了定时器事件被堵塞,在AS3触发一次全部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以多种形式已经遇到此问题。

I've experience this problem in many forms.

public function startTimer() {
  timer = new Timer(3000);
  timer.addEventListener(TimerEvent.TIMER, timerTick, false, 0, true);
  timer.start();
}

private function timerTick(e:TimerEvent) {
  var bubble = new Bubble();
  this.addChild(bubble);
}

泡泡被从显示中删除了一定的时间之后。想象一下,一个水泡沫从屏幕底部的飘了起来,并打顶时得到删除。

Bubble gets removed from the display after a certain amount of time. Imagine a water bubble in the floating up from the bottom of the screen, and getting removed when hitting the top.

如果闪光灯窗口被闲置20分左右,正在创建并在显示屏上显示,然后太多的泡泡的对象。应该只有约5在屏幕上(因为他们可以删除),但也有太多的。

If the flash window is left idle for around 20 minutes, then way too many Bubble objects are created and shown on the display. There should only be around 5 on the screen (because they get removed), but there are way too many.

我觉得由于某种原因定时器事件被堵塞,我们回来的时候到浏览器窗口,所有触发一次。这是使用的Firefox在Mac上,也发生在其他浏览器。

I think for some reason the timer events get clogged and when we come back to the browser window, all triggered at once. This is using firefox on the mac, but also happens in other browsers.

我已经尝试了很多东西,包括重写使用flash.utils.getTimer()(即使用系统时钟)的定时器,并使用递归TweenLite.delayedCall。

I have tried many things, including rewriting the timers using flash.utils.getTimer() (ie using the system clock), and using a recursive TweenLite.delayedCall.

感谢您的任何提示和指针

Thanks for any tips and pointers

推荐答案

我想在Flash Player 10.1,它扼杀播放到2FPS一个新的功能,你已经运行相抵触时,内容是完全不可见的(即当用户切换标签,或滚动屏幕外的内容)。一个Adobe的工程师解释说这这里

I think you've run afoul of a new feature in Flash Player 10.1, where it throttles playback down to 2FPS when the content is completely invisible (i.e when the user switches tabs, or scrolls the content offscreen). An Adobe engineer explains this here.

所以我猜,你的气泡移动和删除自己基于帧的动画或事件。所以,当这限制时,他们开始移动速度要慢得多相比,它们催生了速度。 (即使播放节流,计时器事件的工作大致相同 - 它们发生的机会来了那么频繁,但每​​个事件仍会发生一次,因为最后一个3秒钟通过了第一次机会。)

So I'm guessing that that your bubbles move and remove themselves based on frame animations or events. So when this throttling occurs, they start moving much more slowly compared to the rate they are spawned. (Even with playback throttled, timer events work roughly the same - the chance for them to occur comes less frequently, but each event still occurs at the first opportunity once three seconds have passed since the last one.)

使混合在一起的任何内容的基于帧的和基于时间的行为将会表现不同在10.1当用户改变翼片,这是最终需要preserve性能和电池的设备。最好的解决方法是可能改变你的计时器,以某种基于帧的逻辑,沿着这些线路:

So any content that mixes together frame-based and time-based behaviors is going to behave differently in 10.1 when the user changes tabs, which is ultimately necessary to preserve performance and battery on devices. The best fix is to probably to change your timers to some sort of frame-based logic, along these lines:

public function startTimer() {
    frameCount = 0;
    addEventListener( Event.ENTER_FRAME, onFrame, false, 0, true);
}

private function onFrame(e:Event) {
    frameCount++;
    if (frameCount > waitTimeSeconds * publishedFPS) {
        frameCount = 0;
        timerTick();
    }
}

当然,你也可以改变气泡的定时器完全正常工作,但只是意味着当内容是不可见的选项卡上,每一帧都会有计时器事件废物循环处理一大叠。

Granted, you could also change the bubbles to work entirely on timers, but that just means that when the content is on an invisible tab, every frame there will be a big stack of timer events to waste cycles processing.

这篇关于定时器事件被堵塞,在AS3触发一次全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆