Window being held issue

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.
Post Reply
User avatar
Drakkahn
Prole
Posts: 28
Joined: Sat Jan 17, 2015 11:09 pm

Window being held issue

Post by Drakkahn »

Is there any way to check if the game window is being held, also is there any way to make so the game won't stop when the window is held.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Window being held issue

Post by Jasoco »

No. These are issues with the OS. Windows and OS X do it differently. On OS X it doesn't pause when you hold the window, but it does when you hold on the traffic light buttons. It's an issue with the window management framework Löve uses.

What you can do is limit the dt variable in the main update callback by using math.min(dt, 1/30) or a smaller number. Something reasonable. Then at least when the mouse is let go it'll be as if only a short delay happened.

Also make sure to never program your events to depend on the current time, rather have a separate timer variable in the update callback that you can refer to as this timer will only run when the pausing isn't happening.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Window being held issue

Post by bartbes »

Jasoco wrote:It's an issue with the window management framework Löve uses.
No, these are OS "features".
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Window being held issue

Post by Jasoco »

bartbes wrote:
Jasoco wrote:It's an issue with the window management framework Löve uses.
No, these are OS "features".
Feature, issue, what's the difference. :3

Either way, it's not something that can be disabled right? Best you can do is make sure dt (Delta time) never goes above a certain amount. (Like maybe 1/15th of a second as that would mean things will be fine as long as the game never runs slower than 15FPS.)
User avatar
Drakkahn
Prole
Posts: 28
Joined: Sat Jan 17, 2015 11:09 pm

Re: Window being held issue

Post by Drakkahn »

Can someone please post code of this, all my attempts have failed.

My Attempt

Code: Select all

function love.update(dt)

	dtc_start=love.timer.getTime()
	
	--Process events
	
	dtc=love.timer.getTime()-dtc_start

end
Also for the enemy moving im using:

Code: Select all

self.x=self.x+100*dtc
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: Window being held issue

Post by Doctory »

that is unneeded. instead of dtc, use dt it is already supplied
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Window being held issue

Post by Jasoco »

Just do what I said. At the top of the love.update() function put dt = math.min(dt, 1/30). If you want, change the 30 to 15 or something. It's literally all you need to do to fix this.
User avatar
Drakkahn
Prole
Posts: 28
Joined: Sat Jan 17, 2015 11:09 pm

Re: Window being held issue

Post by Drakkahn »

This is what I now have, however it is not working. If you hold the window long enough all the enemies will end up with the same x and y values.

Code: Select all

function love.update(dt)

	dt=math.min(dt,1/30)

	--run events

end

Code: Select all

self.x=self.x+100*dt
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Window being held issue

Post by Jasoco »

It shouldn't though. Can you provide your .love? Because what happens in a single update frame is that stuff moves at one frames worth of distance. This amount is calculated by Löve's underpinnings running in the background and passing the delta to the update() function. But when the window is held (On Windows, or buttons being pressed on OS X) the underpinnings stop executing but the Lua frontend keeps running. So when Lua goes to grab the current Delta amount it doesn't get anything and will only get something when the mouse is released which at that point calculated Delta Time as the amount of time you held the window titlebar. Which, in some games, will cause it to think you're running at a reallllllly low framerate. So by capping the Delta Time it should only pass 0.3333333333333 as the current Delta.

So I'm confused why it wouldn't fix it for you. So the problem must be lying elsewhere. If you can provide a .love file we can take a look for you.
User avatar
Drakkahn
Prole
Posts: 28
Joined: Sat Jan 17, 2015 11:09 pm

Re: Window being held issue

Post by Drakkahn »

*facepalm*

I thought it was ok to set dt as a global variable, well that ended up being the problem. Thanks a lot for all your help.
Post Reply

Who is online

Users browsing this forum: No registered users and 39 guests