setTimeout or setInterval or requestAnimationFrame

前端 未结 3 1787
小鲜肉
小鲜肉 2020-12-14 18:59

For HTML5 games,with canvas animation for mobile devices.

I\'m facing some performance issues which differ the speed between each device and the others.

3条回答
  •  [愿得一人]
    2020-12-14 19:14

    window.requestAnimFrame = function(){
        return (
            window.requestAnimationFrame       || 
            window.webkitRequestAnimationFrame || 
            window.mozRequestAnimationFrame    || 
            window.oRequestAnimationFrame      || 
            window.msRequestAnimationFrame     || 
            function(/* function */ draw1){
                window.setTimeout(draw1, 1000 / 60);
            }
        );
    }();
       window.requestAnimFrame(draw);
    })();
    

    use this function for all cases

提交回复
热议问题