Laya 分帧加载优化
@author ixenos
Flash中的EnterFrame事件在Laya中等同于Laya.timer.frameLoop(1,...)
1 Laya.timer.frameLoop(1, this, onFrame); 2 3 var curIdx:int = 0; 4 5 var st:Number = 0; 6 7 var tLimit:Number = 1000/Laya.timer.currFrame*0.25;//最大时间不超过一帧所需时间的25%(可调整) 8 9 function onFrame():void{ 10 11 st = new Date().getTime(); 12 for(var i:int = curIdx; i < MAX_COUNT; i++){ 13 //到达时限时,余下script不在当前帧运行 14 if(new Date().getTime() - st > tLitmit){ 15 curIdx = i; 16 return; 17 } 18 doThings(); 19 } 20 21 onComplete(); 22 23 } 24 25 26 27 function doThings(){ 28 29 } 30 31 32 33 function onComplete(){ 34 35 Laya.timer.clear(this, onFrame); 36 37 }