I was wondering how I would make my Love2D game pause when the game loses focus or when I press the ESC button. I am trying to learn Lua but it's hard.
create a bool pause, check for the esc key, if true, swap bool. in update, have an if statement to break out of execution if true. in draw, draw a paused sprite over top?
Don't have any lua experience, just thought I'd try to help.
For losing focus, see this callback:
[url]https://love2d.org/wiki/love.focus[/url]
Again just set your paused variable in that when focus is lost.
[lua]function love.load()
paused = false;
end
function love.draw()
if paused then
--draw something over the rest of the game?
end
end
function love.update(dt)
if not paused then
--put all your update shit in here
end
end
function love.focus(b)
if not b then
paused = true;
end
--A statement unpausing the game when the window is focused again wouldn't be desireable
--AKA it'd annoy the piss out of anyone playing your game
end
function love.keyPressed(key)
if key == "escape" then
paused = not paused;
end
end[/lua]