自定义requestAnimationFrame帧频
生活随笔
收集整理的這篇文章主要介紹了
自定义requestAnimationFrame帧频
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
requestAnimationFrame(callback)觸發(fā)的callback方法會接受一個時間戳參數(shù),所以如果不想直接跟隨瀏覽器系統(tǒng)幀頻的話, 就可以利用這個時間戳參數(shù)來做到自定義幀頻,做法就是當前時間減去所記錄的上一次的時間,如果超過自定義的幀頻時間,就可以真正做渲染了 var fps = 60; var frameDelay = 1 / fps * 1000; var timeRecord = -frameDelay; function render(time){ if(time - timeRecord >= frameDelay) { cube.rotation.x += 0.1; cube.rotation.y += 0.1;
ballMesh.rotation.x += 0.1; ballMesh.rotation.y += 0.1;
line.rotation.y += 0.1;
renderer.render(scene,camera); timeRecord = time; stats.update(); } requestAnimationFrame(render); } render(0); }
ballMesh.rotation.x += 0.1; ballMesh.rotation.y += 0.1;
line.rotation.y += 0.1;
renderer.render(scene,camera); timeRecord = time; stats.update(); } requestAnimationFrame(render); } render(0); }
?
轉(zhuǎn)載于:https://www.cnblogs.com/JD85/p/10112898.html
總結(jié)
以上是生活随笔為你收集整理的自定义requestAnimationFrame帧频的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2018.12.12
- 下一篇: python list 取重复次数