logan-r / vilify

Unleash Your Inner Mad Scientist and Destroy the World (with Ice Cream) in this Open Source HTML5 Game
http://logan-r.github.io/vilify/
GNU General Public License v3.0
32 stars 25 forks source link

requestAnimationFrame #24

Closed sru closed 11 years ago

sru commented 11 years ago

I heard that requestAnimationFrame is more optimized than setTimeout or setInterval. Should we use it?

Here is the cross-browser way:

window.requestAnimFrame = (function() {
    return window.requestAnimationFrame ||
             window.webkitRequestAnimationFrame ||
             window.mozRequestAnimationFrame ||
             window.oRequestAnimationFrame ||
             window.msRequestAnimationFrame ||
             function(/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) {
                 window.setTimeout(callback, 1000/60);
             };
})()

And you can visit this site to control fps.