Okay!
First, you check for love.keyboard.isDown("f") twice. So let's see what that does:
Code: Select all
if the f key is down, then:
make the window fullscreen
else, if the f key is not down then:
if the f key is down then:
make the window not fullscreen
So you see, the last part is never used, because the f key cannot both be down and not down at the same time. So what do you do? Check if the window already is fullscreen with [wiki]love.window.getFullscreen[/wiki]:
Code: Select all
function love.update(dt)
if love.keyboard.isDown("f") then
if love.window.getFullscreen() then
love.window.setFullscreen(false, "desktop")
else
love.window.setFullscreen(true, "desktop")
end
end
end
Now, this works, but it can be shorter:
Code: Select all
function love.update(dt)
if love.keyboard.isDown("f") then
love.window.setFullscreen(not love.window.getFullscreen(), "desktop")
end
end
Okay, but now it checks every frame, so if you keep the f key down just a little bit too long, the game starts to go to fullscreen and back many times per second.
So how do we fix that? With [wiki]love.keypressed[/wiki].
Code: Select all
function love.update(dt)
end
function love.keypressed(key, isrepeat)
if key == "f" then
love.window.setFullscreen(not love.window.getFullscreen(), "desktop")
end
end