/** | |
* Provides requestAnimationFrame in a cross browser way. | |
* @author paulirish / http://paulirish.com/ | |
*/ | |
if ( !window.requestAnimationFrame ) { | |
window.requestAnimationFrame = ( function() { | |
return window.webkitRequestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
window.oRequestAnimationFrame || | |
window.msRequestAnimationFrame || | |
function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) { | |
window.setTimeout( callback, 1000 / 60 ); | |
}; | |
} )(); | |
} |
This comment has been minimized.
This comment has been minimized.
Fixed! :-) |
This comment has been minimized.
This comment has been minimized.
hey i wrote that! gregg stealing my glory. >:) |
This comment has been minimized.
This comment has been minimized.
Now you know how it feels! (Google Axis ;D) Now seriously, he didn't specify... he pasted the snippet on a issue: I'll change the credit ;) |
This comment has been minimized.
This comment has been minimized.
Paul, is this the one that you wrote? https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/demos/common/webgl-utils.js (end of the file) |
This comment has been minimized.
This comment has been minimized.
Basically. Gregg Tavares had an uglier one there before and I rewrote it to what I just posted: http://paulirish.com/2011/requestanimationframe-for-smart-animating/ Then Gregg made it a proper polyfill with the full |
This comment has been minimized.
This comment has been minimized.
Should it not be |
This comment has been minimized.
This comment has been minimized.
paul: I see I see! :) louisstow: If you have the setTimeout at the befinning of the loop you shouldn't get delays. |
This comment has been minimized.
This comment has been minimized.
surely there should be something to sync animations - so they all occur in the same event loop ?
|
This comment has been minimized.
This comment has been minimized.
How would you modify the latest jQuery with this shim and should I expect any performance improvements?? I believe this is the one line that sets up the animation timing |
This comment has been minimized.
This comment has been minimized.
jquery 1.6.1 supported this:
|
This comment has been minimized.
This comment has been minimized.
setTimeout is many times inaccurate, and so is setInterval. More importantly, however, setTimeout(1000/60) doesn't take into account where we are wrt to the next vsync (it always assume we have the full frame time ahead of us), so it needs to align to the "independent" intervals of an imaginary vsync signal.
|
This comment has been minimized.
This comment has been minimized.
My animation is magically smooth now! ;) |
This comment has been minimized.
This comment has been minimized.
just leaving there CoffeeScript code snippet ###
# Provides requestAnimationFrame in a cross browser way.
# @author paulirish / http://paulirish.com/
###
unless window.requestAnimationFrame
window.requestAnimationFrame = window.webkitRequestAnimationFrame or
window.mozRequestAnimationFrame or
window.oRequestAnimationFrame or
window.msRequestAnimationFrame or
(callback, element) -> window.setTimeout callback, 1000 / 60 |
This comment has been minimized.
This comment has been minimized.
hi, what is the diff to the following last post? http://codereview.stackexchange.com/questions/60216/gameloop-with-requestanimationframe (cc GameAlchemist answered Aug 19 '14 at 11:58) |
This comment has been minimized.
This comment has been minimized.
I cant understand one thing, why do we need to use the delay as |
This comment has been minimized.
This comment has been minimized.
Hi @mrdoob, why do we need the |
This comment has been minimized.
This comment has been minimized.
@buttflattery I know this is an old post, but I'm replying for any future people who see this. You use |
This comment has been minimized.
You can remove the
window.requestAnimationFrame ||
bit since you will only get here whenwindow.requestionAnimationFrame
is not already "truthy".:-)