我的游戏中有大约 10000 个对象,并且在不移动鼠标时正好是 60(最大)FPS。但是,当您开始在圆圈中移动鼠标时,FPS 试图达到 30,平均为 45。当您停止鼠标时,它立即变为 60(因此程序失去了它的心跳)。SWF 独立运行 - 无需任何浏览器。
我删除了所有MouseEvent.MOUSE_MOVE
听众,mouseEnabled=false
并mouseChildren=false
为主要课程制作了和。
我将我的 FPS 从 12 一个一个地提高到 60 - 我为我出生的每一帧命名,看着他们中的 15 个因无所事事而死亡真的很痛苦......
示例代码:
public class Main extends Sprite
{
private var _periods : int = 0;
/** Idling FPS is 23. Move mouse to drop FPS to 21.*/
public function Main() : void
{
//true if need to drop FPS to 18 instead of 21 moving mouse:
const readyToKill2MoreFrames : Boolean = true;
if ( readyToKill2MoreFrames )
{
var ellipse : Sprite = new Sprite;
ellipse.graphics.beginFill( 0x00FF00 );
ellipse.graphics.drawEllipse( 300, 300, 400, 200 );
ellipse.graphics.endFill();
addChild( ellipse );
//uncomment to fall only to 21 instead of 18:
/*ellipse.mouseChildren = false;
ellipse.mouseEnabled = false;*/
}
var fps : TextField = new TextField;
//uncommenting doesn't change FPS:
//fps.mouseEnabled = false;
addChild( fps );
fps.text = "???";
fps.scaleX = fps.scaleY = 3;
var timer : Timer = new Timer( 1000 );
timer.addEventListener( TimerEvent.TIMER, function( ... args ) : void
{
fps.text = _periods.toString();
_periods = 0;
} );
timer.start();
addEventListener( Event.ENTER_FRAME, function( ... args ) : void
{
//seems like PC is too fast to demonstrate mouse movement
// drawbacks when he has nothing else to do, so let's make
// his attention flow:
for ( var i : int = 0; i < 500000; ++i )
{
var j : int = 2 + 2;
}
++_periods;
} );
}
}