Page 1 of 1

love.screen module

Posted: Mon Apr 25, 2011 1:01 pm
by TsT
Hello,

After LOVE API naming discuss topic...
I decide to made my own love.screen module to provide a better way (my opinion) to manage the screen (caption, resolution, ...)

I think, the main improvement is about the setMode(...)

How to use the module ?

Code: Select all

function love.load()
        require("love.screen") -- load the love.module
        love.screen.init() -- Mandatory : it create the main screen.
        screen = love.screen.getScreen()
end

How to change the resolution to 640x480 ?

Code: Select all

screen:setMode(640, 480)
How to get a 300x300 windowed (not fullscreened)

Code: Select all

screen:setMode(300, 300, false)
How to keep current screen resolution/settings but change the fsaa to 2

Code: Select all

screen:setMode(nil, nil, nil, nil, 2)
Documentation :
The functions that are equal to the love.graphics one :

Code: Select all

screen:getCaption()
screen:setCaption(title)
screen:checkMode(width, height, fullscreen)
screen:getModes()
screen:toggleFullscreen()
screen:getHeight()
screen:getWidth()
The setMode function are like the love.graphics one but manage the nil value like the getMode() (see below):

Code: Select all

screen:setMode(width, height, fullscreen, vsync, fsaa)
I'm also implement missing functions like :

Code: Select all

screen:getFullscreen() -- true if currently fullscreen, false if not
screen:getVsync() -- get the vsync value used by the last mode change (or the default if defined in love.conf)
screen:getFsaa() -- get the fsaa value used by the last mode change (or the default if defined in love.conf)
screen:getMode(...) -- Note: it's not the getModes() see below...
screen:getMode() -- get the current screen settings : width, height, fullscreen, vsync, fsaa
screen:getMode(width, height, fullscreen, vsync, fsaa) -- return the current screen settings but overwrite with the argument passed, see sample below.
Sample of use :

Get the screen handler

Code: Select all

        screen = love.screen.getScreen()
-- or
        screen = love.screen.getScreen("main")
Change Caption

Code: Select all

        screen:setCaption("this is a test caption")
Change the resolution to 640x480 and keep current other settings

Code: Select all

        local width, height, fullscreen, vsync, fsaa = screen:getMode()
        screen:setMode(640, 480, fullscreen, vsync, fsaa)
        -- or
        screen:setMode(screen:getMode(640, 480, nil, nil, nil))
Switch to vsync = true

Code: Select all

        screen:setMode(screen:getMode(nil, nil, nil, true, nil))
Toggle vsync

Code: Select all

        screen:setMode(screen:getMode(nil, nil, nil, not screen:getVsync() , nil))
Toggle Fullscreen

Code: Select all

        screen:toggleFullscreen()
-- or
        screen:setMode(nil, nil, not screen:getFullscreen(), nil , nil))
Download love.screen.zip - 2011.04.21

EDIT: the module could be able to manage multiple screen object (but not checked, and not really usefull for now)