Del*_*ani 2 html javascript html5 canvas
In this page that counts the number of frames rendered and prints the FPS onto the canvas, we can see that it tops out at 100fps, which seems suspicious at the least. Why is this?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Canvas FPS artificial limiting</title>
</head>
<body>
<canvas id="c" width="320" height="240"></canvas>
<script>
var c = document.getElementById('c').getContext('2d'),
f = 0,
s = new Date;
setInterval(function() {
c.clearRect(0, 0, 320, 240);
c.fillText(++f / ( ((+new Date) - s) / 1000 ), 8, 16);
}, 0);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
I'm currently having this problem on Firefox 4.0b6 and Ubuntu 10.10 beta.
Del*_*ani 12
I got it! According to this page:
https://developer.mozilla.org/en/window.setTimeout#Minimum_delay_and_timeout_nesting
setTimeout并且setInterval在Firefox(每秒100次迭代)上被钳位至少10ms,以避免锁定和UI性能下降.这意味着,低于此值的延迟值使用10ms(最多100fps).
这不是画布问题; 它是对定时器最小延迟的人为限制.
编辑:进一步阅读表明Chrome可以进行4ms的钳制,可以对定时器进行250fps的人工限制.