Framerate increases when window is not in focus

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Knuxchan
Prole
Posts: 15
Joined: Wed Apr 03, 2013 4:06 am

Framerate increases when window is not in focus

Post by Knuxchan »

I don't know if this is a bug with Zerobrane, or if it's something that happens with any LOVE file that's tested. When I run my program (whether running as 'scratchpad' or running regularly), if the game window is not in focus, then the framerate will increase significantly. I noticed this because I have a continuous scrolling background that is supposed to scroll very slow, but if the window is not in focus, then the background scrolls really fast. How do I prevent the framerate from increasing? Has anyone else had this problem?
Wojak
Party member
Posts: 134
Joined: Tue Jan 24, 2012 7:15 pm

Re: Framerate increases when window is not in focus

Post by Wojak »

Well its quite oposite...
Wten the window gets out of focus the FPS may drop to less than 1, and the lower the FPS, the larger the dt gets, so if you sue the dt it may seam that the stuff is moving faster...
The solution is to lomit the dt like this:

Code: Select all

dt = math.min(dt, 0.09)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Framerate increases when window is not in focus

Post by bartbes »

Wojak wrote:so if you sue the dt it may seam that the stuff is moving faster...
Then you're using dt completely wrong.

The answer is probably that you've got an os that kind of knows what it's doing, and optimizing out the draws to whatever's not on-screen, however, if framerate influences the speed at which your game runs, you should be using dt.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Framerate increases when window is not in focus

Post by Lafolie »

If your game window loses focus then it's usually a good idea to pause the gameplay, especially for action-oriented games.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Wojak
Party member
Posts: 134
Joined: Tue Jan 24, 2012 7:15 pm

Re: Framerate increases when window is not in focus

Post by Wojak »

bartbes wrote:
Wojak wrote:so if you sue the dt it may seam that the stuff is moving faster...
Then you're using dt completely wrong.

The answer is probably that you've got an os that kind of knows what it's doing, and optimizing out the draws to whatever's not on-screen, however, if framerate influences the speed at which your game runs, you should be using dt.
Note that we are talking about FPS below 1 (0.5 or so), and this happens on widows (at least vista and 7) when you drag the love window while the game is running (this is undetected by love.focus)...

Limiting dt solves the problem (the code from my previous post), but the game will slow down when the fps drops (with 0.09 if will start sloing down below 11 FPS witch is way bellow playability level)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Framerate increases when window is not in focus

Post by bartbes »

That still shouldn't speed up your game, it will make things happen extremely fast for a single frame, but the actual average speed is correct. It does tend to mess with physics simulations and stuff, but again it still doesn't mean it's faster.
Knuxchan
Prole
Posts: 15
Joined: Wed Apr 03, 2013 4:06 am

Re: Framerate increases when window is not in focus

Post by Knuxchan »

Sorry, I meant the frame rate decreases, meaning everything is getting super fast when the window isn't in focus.

So would it just make sense to halt the entire game when the window is not in focus, like Lafolie's suggestion? Or is there any way to keep the framerate consistent whether it's in focus or not? Does pausing/halting a LOVE game reduce the amount of CPU resources being used? Or does it use more resources?
User avatar
Ragzouken
Citizen
Posts: 84
Joined: Fri Aug 10, 2012 7:59 am
Contact:

Re: Framerate increases when window is not in focus

Post by Ragzouken »

You should post a .love where this can be observed/checked by someone - it sounds like you aren't using dt correctly, as bartbes suggested. When you vary things by time you should have a factor of dt in there.

Code: Select all

function love.update(dt)
     x = x + 7 * dt -- dt is the amount of time in seconds that has passed since the last update, so x will increase by 7 each second
end
Knuxchan
Prole
Posts: 15
Joined: Wed Apr 03, 2013 4:06 am

Re: Framerate increases when window is not in focus

Post by Knuxchan »

There's a love file in my previous topic: http://love2d.org/forums/viewtopic.php? ... 8&start=10

But I don't understand how the dt increases just because the window is not in focus. If I make the window back in focus again, then everything is normal.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Framerate increases when window is not in focus

Post by substitute541 »

There's a reason why DT is there; so that things can run and look pretty much the same and any framerate. So when FPS decreases, DT increases, and it still looks the same. Even when FPS is some value less than 1.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 220 guests