The ScreenManager library is a state manager at heart which allows some nifty things, like stacking multiple screens on top of each other.
It also offers hooks for most of LÖVE's callback functions. Based on the type of callback the calls are rerouted to either only the active screen (love.keypressed, love.quit, ...) or to all screens (love.resize, love.visible, ...).
For a more complete example check out the example branch in this repository.
This is a simple example of how the ScreenManager should be used (note: You will have to change the paths in the example to fit your setup).
-- main.lualocalScreenManager=require('lib.ScreenManager')
functionlove.load()
localscreens= {
main=require('src.screens.MainScreen')
}
ScreenManager.init(screens, 'main')
endfunctionlove.draw()
ScreenManager.draw()
endfunctionlove.update(dt)
ScreenManager.update(dt)
endNote how MainScreen inherits from Screen.lua. This isn't mandatory, but recommended since Screen.lua already has templates for most of the callback functions.
-- MainScreen.lualocalScreen=require('lib.Screen')
localMainScreen= {}
functionMainScreen.new()
localself=Screen.new()
localx, y, w, h=20, 20, 40, 20functionself:draw()
love.graphics.rectangle('fill', x, y, w, h)
endfunctionself:update(dt)
w=w+2h=h+1endreturnselfendreturnMainScreenAn online documentation is available here.