Laya 分帧加载优化
@author ixenos
Flash中的EnterFrame事件在Laya中等同于Laya.timer.frameLoop(1,...)
Laya.timer.frameLoop(1, this, onFrame); var curIdx:int = 0; var st:Number = 0; var tLimit:Number = 1000/Laya.timer.currFrame*0.25;//最大时间不超过一帧所需时间的25%(可调整) function onFrame():void{ st = new Date().getTime();
for(var i:int = curIdx; i < MAX_COUNT; i++){
//到达时限时,余下script不在当前帧运行
if(new Date().getTime() - st > tLitmit){
curIdx = i;
return;
}
doThings();
} onComplete(); } function doThings(){ } function onComplete(){ Laya.timer.clear(this, onFrame); }