Page 1 of 1

Any way to proper toggleFullscreen function

Posted: Tue Jul 24, 2018 4:37 pm
by greycoder
Hellow everyone, I've tried coding like that

Code: Select all

love.window.setFullscreen(not love.window.getFullscreen())
But in case of 'fullscreen mode' > 'windowed mode' you get window adjusted to screen size
Then I coded

Code: Select all

local fsc_val = love.window.getFullscreen()
if fsc_val then
	love.window.updateMode(_config.window.width, _config.window.height, {fullscreen = false})
else
	love.window.setFullscreen(true)
end
where _config is some global to link to conf table. Is there better way to code toggleFullscreen function without making globals?

Re: Any way to proper toggleFullscreen function

Posted: Thu Jul 26, 2018 3:13 am
by Duck Duckinson
https://love2d.org/wiki/Config_Files

Create a file in the same directory as your main.lua named "conf.lua"
Inside you put:

function love.conf(t)
t.window.fullscreen = true
end

Re: Any way to proper toggleFullscreen function

Posted: Thu Jul 26, 2018 4:54 am
by Nixola
First of all: default fullscreen is evil.
Second, the question was about toggling it, not setting it.

Re: Any way to proper toggleFullscreen function

Posted: Thu Jul 26, 2018 8:27 am
by zorg
From the wiki: love.window.setFullscreen
If fullscreen mode is entered and the window size doesn't match one of the monitor's display modes (in normal fullscreen mode) or the window size doesn't match the desktop size (in 'desktop' fullscreen mode), the window will be resized appropriately. The window will revert back to its original size again when fullscreen mode is exited using this function.
Basically, it should go back to the size the window had before going to fullscreen.