Page 1 of 1

Pausing.

Posted: Thu Dec 29, 2011 9:17 pm
by baconhawka7x
I was wondering if there was a way to freeze the framerate completely? I was going to use this to pause the game when the window is unfocused or you push "p".

Thanks:-)

Re: Pausing.

Posted: Thu Dec 29, 2011 9:21 pm
by thelinx
To put it in the simplest terms possible, turn

Code: Select all

function love.update(dt)
  ...
end
into

Code: Select all

paused = false
function love.keypressed(key)
  if key == "p" then
    paused = not paused
  end
end
function love.update(dt)
  if paused then return end
  ...
end

Re: Pausing.

Posted: Thu Dec 29, 2011 9:31 pm
by IMP1
And for when you lose focus:

Code: Select all

function love.focus(f)
  if not f and not paused then
    pause = true
  end
end

Re: Pausing.

Posted: Thu Dec 29, 2011 10:53 pm
by clickrush
why would you write "not false" instead of "true" ?

Re: Pausing.

Posted: Thu Dec 29, 2011 10:58 pm
by thelinx
clickrush wrote:why would you write "not false" instead of "true" ?
Whoops, meant to write "not paused".

Re: Pausing.

Posted: Fri Dec 30, 2011 2:19 am
by baconhawka7x
thelinx wrote:To put it in the simplest terms possible, turn

Code: Select all

function love.update(dt)
  ...
end
into

Code: Select all

paused = false
function love.keypressed(key)
  if key == "p" then
    paused = not paused
  end
end
function love.update(dt)
  if paused then return end
  ...
end
Wow, that's so simple. I cant believe I didn't think of thatXD thanks!

Re: Pausing.

Posted: Fri Dec 30, 2011 10:51 am
by Robin
That's also the way Invader does it, by the way.