setTimeout or setInterval or requestAnimationFrame

前端 未结 3 1790
小鲜肉
小鲜肉 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:30

    OPTIMIZATION requestAnimationFrame() since its introduction was very CPU friendly, causing animations to stop if the current window or tab is not visible.

    https://flaviocopes.com/requestanimationframe/

     var count = 0;
        const IDS = requestAnimationFrame(repeatOften);
    
            function repeatOften() {
                count++;
                if(count > 4 ){
                    // cancelAnimationFrame (IDS);
                     console.warn('finish');
                     return;
                }
                console.log('init' + count);
                // Do whatever
                requestAnimationFrame(repeatOften);
            }
    

提交回复
热议问题