flashPlayer自动降频后webgame处理技巧
/** * EnterFrame事件处理 */ private var frameRate:uint = stage.frameRate; private var halfRate:uint = frameRate >> 1; private var intervalTime:uint = 1000/frameRate; private var deltaTime:Number = 0; private var lastTime:uint = 0; private function enterFrame(e:Event):void { //计算实际帧频 var nowTime:uint = getTimer(); deltaTime = nowTime - lastTime; lastTime= nowTime; var realFrame:uint = uint(1000/deltaTime);//上一帧的实际帧频 if(realFrame >= halfRate){ gameLoop(); }else{ //flashplayer最小化后要做的事 trace('浏览器最小化了'); /** 补帧 */ var tweenFrames:uint = frameRate/realFrame; for(var i:uint=0; i<tweenFrames; i++){ gameLoop(); } } }
当浏览器最小化后,通过补帧来让逻辑与视图同步。