Sia*_*agh 10 javascript three.js requestanimationframe
我正在研究Three.js的一些个人项目.我正在使用requestAnimationFrame
功能.我想每2秒调用一次函数.我搜索但我找不到任何有用的东西.
我的代码是这样的:
function render() {
// each 2 seconds call the createNewObject() function
if(eachTwoSecond) {
createNewObject();
}
requestAnimationFrame(render);
renderer.render(scene, camera);
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
hin*_*ost 10
requestAnimationFrame
将单个参数传递给您的回调,该回调指示requestAnimationFrame
触发回调时的当前时间(以毫秒为单位).您可以使用它来计算render()
呼叫之间的时间间隔.
var last = 0; // timestamp of the last render() call
function render(now) {
// each 2 seconds call the createNewObject() function
if(!last || now - last >= 2*1000) {
last = now;
createNewObject();
}
requestAnimationFrame(render);
renderer.render(scene, camera);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4178 次 |
最近记录: |