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: 484
Joined: Mon Nov 21, 2011 7:05 am
Contact:

Pausing.

Post by baconhawka7x » Thu Dec 29, 2011 9:17 pm

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: 848
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Pausing.

Post by thelinx » Thu Dec 29, 2011 9:21 pm

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: 41
Joined: Mon Oct 03, 2011 8:46 pm

Re: Pausing.

Post by IMP1 » Thu Dec 29, 2011 9:31 pm

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 » Thu Dec 29, 2011 10:53 pm

why would you write "not false" instead of "true" ?
Sry about my english.

User avatar
thelinx
The Strongest
Posts: 848
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Pausing.

Post by thelinx » Thu Dec 29, 2011 10:58 pm

clickrush wrote:why would you write "not false" instead of "true" ?
Whoops, meant to write "not paused".

User avatar
baconhawka7x
Party member
Posts: 484
Joined: Mon Nov 21, 2011 7:05 am
Contact:

Re: Pausing.

Post by baconhawka7x » Fri Dec 30, 2011 2:19 am

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 » Fri Dec 30, 2011 10:51 am

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 18 guests