Processing.js 计时器 [英] Processing.js timer

查看:29
本文介绍了Processing.js 计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Processing.js 开发应用程序.

I am developing an application using Processing.js.

在绘图循环的每一步,我将帧数增加一个 frame++ .

At each step in the drawing loop I increment the number of frames by one frame++ .

我想知道过去了多少时间.目前为了让时间过去(知道我的应用程序设置为以 60FPS 运行),我喜欢这样: time=frame/60 .但这只有在应用始终以精确的 FPS 运行时才有效,而且我们都知道情况并非如此,因为它取决于用户的硬件.

I want to know how much time has passed. Currently to get the time passed (knowing that my application is set to run on 60FPS) I do like so: time=frame/60 . But this only works if the application always run at exactly FPS and we all know that's not the case cause it depends on the users hardware.

我希望计时器非常准确(只有 0.0001 秒的误差).

I want the timer to be pretty accurate (having only like 0.0001s error).

也欢迎提出一些用于计算 now() 和 start_time() 之间差异的 javascript 算法.

Suggesting some javascript algorithm for calculating the difference between now() and start_time() is also welcome.

推荐答案

您可以将开始时间存储在一个变量中.

You can store the start time at a variable.

然后随时创建一个新的计时器并从中减去开始时间变量..结果将以毫秒为单位的差异..

Then create a new timer whenever you want and subtract the start time variable from it.. The result will be the difference in milliseconds..

您还可以使用实际时间除以帧计数器来获得应用程序的准确平均帧速率..

You can also use the actual time divided by the frames counter to get an accurate average frame-rate of your application..

类似的东西

var startTimer = new Date(); // at start (once)

只要你想检查

var passed = new Date() - startTimer; // in milliseconds

演示在 http://jsfiddle.net/gaby/CF4Ju/

这篇关于Processing.js 计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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