Page 1 of 2
Framerate increases when window is not in focus
Posted: Mon Apr 08, 2013 4:16 am
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?
Re: Framerate increases when window is not in focus
Posted: Mon Apr 08, 2013 6:02 am
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:
Re: Framerate increases when window is not in focus
Posted: Mon Apr 08, 2013 3:16 pm
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.
Re: Framerate increases when window is not in focus
Posted: Mon Apr 08, 2013 5:42 pm
by Lafolie
If your game window loses focus then it's usually a good idea to pause the gameplay, especially for action-oriented games.
Re: Framerate increases when window is not in focus
Posted: Mon Apr 08, 2013 6:06 pm
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)
Re: Framerate increases when window is not in focus
Posted: Mon Apr 08, 2013 7:04 pm
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.
Re: Framerate increases when window is not in focus
Posted: Mon Apr 08, 2013 8:52 pm
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?
Re: Framerate increases when window is not in focus
Posted: Mon Apr 08, 2013 11:55 pm
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
Re: Framerate increases when window is not in focus
Posted: Tue Apr 09, 2013 12:45 am
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.
Re: Framerate increases when window is not in focus
Posted: Tue Apr 09, 2013 2:46 am
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.