[LayaAir 2.0]requestAnimationFrame在90或120Hz刷新屏幕下的表现
Laya帧循环依赖requestAnimationFrame函数,而requestAnimationFrame刷新依赖屏幕刷新率,那在高帧率屏幕上依赖帧循环的处理不是都会被加速吗,我看引擎源码是没有对最高帧率做处理的。身边找不到高帧频手机测试,所以没有做demo测试,望大佬们解答,谢谢。
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
Laya_XS
赞同来自:
liudong95
赞同来自:
(function () {
var lastTimer = 0;
var rAF = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame;
window.requestAnimationFrame = rAF ? stTimeWithRAF : stTime;
function stTime(callback) {
let currTime = performance.now();
let elapseTime = Math.max(0, currTime - lastTimer);
let timeToCall = Math.max(0, 16.7 - elapseTime);
window.setTimeout(callback, timeToCall);
lastTimer = currTime + timeToCall;
}
function stTimeWithRAF(callback) {
let currTime = performance.now();
let elapseTime = Math.max(0, currTime - lastTimer);
let timeToCall = Math.max(0, 16.7 - elapseTime);
window.setTimeout(function () {
rAF(callback);
}, timeToCall);
lastTimer = currTime + timeToCall;
}
}());