Pausing Game

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
whopunk123
Prole
Posts: 2
Joined: Sat Feb 25, 2012 11:06 pm

Pausing Game

Post by whopunk123 » Sat Feb 25, 2012 11:11 pm

Hi

When I pause the game with to escape key I would text to come up saying "GAME PAUSED" I can do this but it only stays up for like 1 sec and I want it to stay up till the users presses the escape key again

Heres my code so far:

Code: Select all

if key == 'escape' then
      love.graphics.print("THE GAME IS PAUSED", 10, 250, 0, 2, 2)
   end
Thanks

User avatar
Nixola
Inner party member
Posts: 1940
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Pausing Game

Post by Nixola » Sat Feb 25, 2012 11:31 pm

Code: Select all

--in Keypressed
if key == 'escape' then
  somevariable = not somevariable  --toggles the variable between true and false
end

--in love.draw()
  if somevariable == true then 
    love.graphics.print('THE GAME IS PAUSED', 10, 250, whatever
  end
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

whopunk123
Prole
Posts: 2
Joined: Sat Feb 25, 2012 11:06 pm

Re: Pausing Game

Post by whopunk123 » Sat Feb 25, 2012 11:36 pm

Thanks works great :awesome:

coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Pausing Game

Post by coffee » Sat Feb 25, 2012 11:45 pm

whopunk123 wrote:Thanks works great :awesome:
When you understand well the callback basics of LOVE and how to update and draw things all will be easier

https://love2d.org/wiki/Tutorial:Callback_Functions

Code: Select all

function love.load()
	pause = false
end

function love.update(dt)
	function love.keypressed(key, unicode)
		if key == 'p' then pause = not pause end
	end
end

function love.draw()
	if pause then love.graphics.print("Game is paused",0,0) else 
	love.graphics.print("Game is running",0,0) end
end

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Pausing Game

Post by bartbes » Sun Feb 26, 2012 11:54 am

I would strongly suggest against using an else like that, wrapping your entire function in an if statement because you want to pause seems highly invasive, it's better to just return from the if case.

User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Pausing Game

Post by MarekkPie » Sun Feb 26, 2012 2:55 pm

bartbes wrote:I would strongly suggest against using an else like that, wrapping your entire function in an if statement because you want to pause seems highly invasive, it's better to just return from the if case.
AKA

Code: Select all

function love.draw()
    if pause then love.graphics.print("Game Paused", 0, 0) return end
    -- Unpaused code
end

User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Pausing Game

Post by tentus » Sun Feb 26, 2012 3:26 pm

Also, this:

Code: Select all

function love.update(dt)
   function love.keypressed(key, unicode)
      if key == 'p' then pause = not pause end
   end
end
is wrong. Do it like this:

Code: Select all

function love.update(dt)
   -- do stuff
end
function love.keypressed(key, unicode)
   if key == 'p' then pause = not pause end
end
Kurosuke needs beta testers

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 26 guests