I need help on lag problem

4 posts

Flag Post

I made a game and it always gets to a point where it lags like mad. Is there a ways so that when it gets to that point it automatically goes to low quality.

 
Flag Post

here you go:
when the FPS drops under “minFPS” it lowers the quality
it checks the frame rate every “checkInterval” frames

var lastFrameTime:Number;
var minFPS = 20;
var frameCount:Number = 0;
var checkInterval = 20;
function onEnterFrame() {
if(frameCount%checkInterval==0) {
var time:Number = (new Date()).getTime();
if((time – lastFrameTime) / checkInterval > (1000 / minFPS)) {
switch(_quality) {
case “BEST”:
_quality = “HIGH”;
break;
case “HIGH”:
_quality = “MEDIUM”;
break;
case “MEDIUM”:
_quality = “LOW”;
break;
}

}
//trace(_quality+" "+1000/((time – lastFrameTime)/20))
lastFrameTime = time;
frameCount = 0
}
frameCount++
}

 
Flag Post

From my experience, you aren’t gonna get a huge boost to performance just shifting quality to low. You should examine your methods for scene management and the number of objects on the screen and try to keep the complexity of the scene lower so you don’t hit performance spikes. Do you know why it starts lagging? Is it a point where there’s a ton of objects displaying at once? Do you have a really complex loop that starts running every frame? Do some in depth analysis on your code and you’ll probably find out what’s being inefficient.

 
Flag Post

You could make it so that when it gets to that point, less important scripts which were running every frame are made to run every other frame or every third frame (or every nth frame until you balance the lag with not breaking the game).

ex)


framesPassing++;
if ((!LagTime) || (!(framesPassing%2))) {
// Do something every frame until LagTime is true, then only do it every other frame
}

I’d try this before lowering the quality as this would be less noticeable to the player and less likely to break their immersion.