[How to] use the resolution of the desktop

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

[How to] use the resolution of the desktop

Post 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.
Last edited by Boolsheet on Sat May 07, 2011 3:56 pm, edited 5 times in total.
Shallow indentations.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

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

Post by BlackBulletIV »

Thanks for that. Very informative. :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], zingo and 7 guests