ActionScript中的Event.ENTER_FRAME事件的JavaScript的版本? [英] JavaScript's version of ActionScript's Event.ENTER_FRAME event?

查看:148
本文介绍了ActionScript中的Event.ENTER_FRAME事件的JavaScript的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习JavaScript,我想知道的JavaScript是否有一个事件监听器就像动作的ENTER_FRAME。基本上,我希望这个事件监听器监听所有的时间,而不仅仅是等待事件的任何特定实例(鼠标,键盘事件)。

I am trying to learn JavaScript and I am wondering whether JavaScript has a event listener just like ActionScript's ENTER_FRAME. Basically, I want this event listener to listen "all the time" not just wait for any particular instance (mouse click, keyboard event) of event.

推荐答案

您正在寻找的setInterval(FUNC,时间)。在使其工作就像ENTER_FRAME的话,那么你会做的时间非常少。所以,如果你想模仿,都说30倍帧速率第二个:

You're looking for setInterval(func, time). In the case of making it work like ENTER_FRAME, then you would make time very small. So, if you wanted to imitate a frame rate of say, 30 times a second:

 // you will need to make sure you have good scoping around the function param.
 setInterval(function(){console.log('enterframe')}, 33) 
 // 33 is about 1000 milliseconds / 30.

其实,的setInterval 是Flash太 - flash.utils.setInterval

Actually, setInterval is in Flash too -- flash.utils.setInterval.

作为附带说明 - 不幸的是,的setInterval (在Flash和JS)可以工作对当地的刷新率。在Flash ENTER_FRAME避免了这一点 - 你渲染时,SWF重新呈现。在浏览器中,那么,的setInterval 根本无法做到这一点。

As a side note -- unfortunately, setInterval (in both Flash and JS) can work against the native refresh rate. In Flash ENTER_FRAME avoids this -- you render when the swf re-renders. In the browser, well, setInterval simply can't do that.

这篇关于ActionScript中的Event.ENTER_FRAME事件的JavaScript的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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