Pausing.

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
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Pausing.

Post 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:-)
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Pausing.

Post 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
Last edited by thelinx on Thu Dec 29, 2011 10:57 pm, edited 1 time in total.
Reason: not false -> not paused
User avatar
IMP1
Prole
Posts: 43
Joined: Mon Oct 03, 2011 8:46 pm

Re: Pausing.

Post 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
User avatar
clickrush
Citizen
Posts: 83
Joined: Tue Dec 13, 2011 12:50 am

Re: Pausing.

Post by clickrush »

why would you write "not false" instead of "true" ?
Sry about my english.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Pausing.

Post by thelinx »

clickrush wrote:why would you write "not false" instead of "true" ?
Whoops, meant to write "not paused".
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: Pausing.

Post 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!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Pausing.

Post by Robin »

That's also the way Invader does it, by the way.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests