Page 1 of 1

[How to] use the resolution of the desktop

Posted: Fri Jan 28, 2011 7:44 pm
by Boolsheet
There's always the chance that someone will run your game on a system with a weird resolution. Some small netbooks, for example, don't have a display height of 600, which is problematic with the default 800x600 of LÖVE.

Fortunately you can make LÖVE use the desktop resolution if you set the width and height to 0.

Here's an example for LÖVE 0.7.1 and 0.7.2:

conf.lua

Code: Select all

function love.conf(t)
    t.screen.width = 0
    t.screen.height = 0
end
The game will now start up with the desktop resolution.

Use love.graphics.getWidth() and love.graphics.getHeight() if you want to switch to another resolution, but save the desktop width and height:

main.lua

Code: Select all

function love.load()
    desktopWidth = love.graphics.getWidth()
    desktopHeight = love.graphics.getHeight()

    love.graphics.setMode(1280, 720, false, true, 0)
end

if you're still using LÖVE 0.7.0 you have to do it this way:

conf.lua

Code: Select all

function love.conf(t)
    t.screen = nil    -- LÖVE will not create a window if we nil this table
end
main.lua

Code: Select all

function love.load()
    love.graphics.setMode(0, 0, false, true, 0)   -- Sets the resolution to the size of the desktop
end
Edits
19-02-2011: With 0.7.1 released it's better to point at the easier version first.
07-04-2011: Deleted the stuff about it being only possible once.

Re: [How to] use the resolution of the desktop

Posted: Sat Jan 29, 2011 10:04 am
by BlackBulletIV
Thanks for that. Very informative. :)