To intensify the amount of error here:
You are creating the function 100 times per second but it ins not even used once.
Any usage would be outside of this function
This is a fixed version:
Code: Select all
function love.load()
function love.keypressed(key, unicode)
if key == 'p' then pause = not pause end
end
end
function love.update(dt)
if not pause then
-- do something when the game is paused
end
end
But as said in another thread yesterday, if cases that are looped 100 times a second just for the sake of pause is still pause is a bit messy. Personally i prefer the renaming scheme:
Code: Select all
function love.keypressed(key, unicode)
if key == 'p' then love.update,switch = switch,love.update end
end
function run(dt)
-- game
end
function pause(dt)
--pause screen
end
love.update=run
switch=pause
love.update starts() out being identical to run() and switch() is pause(), now whenever p is pressed they do a switchteroo.
There are many more ways to make a pause screen tho.
If there are no other states you can even be pretty slim profile:
Code: Select all
function love.keypressed(key, unicode)
if key == 'p' then love.update = love.update and nil or run end
end
Since update actually moves numbers but not doing the render this solution freezes the screen _looking_ just perfectly.
For advanced consideration if you are into perfection: This methods pause the movement of objects on the screen, but you are still rendering them new every frame so this pause screen will still take cpu/gpu. Ideally one would want to freeze the entire game loop by either go into a dummy loop with less FPS or halt everything with love.event.wait().
That is not something expected from a hobby game tho.