You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ScreenManager library is a state manager at heart which allows some nifty things, like stacking multiple screens on top of each other.
4
+
5
+
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, ...).
6
+
7
+
## Example
8
+
9
+
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).
10
+
11
+
```
12
+
#!lua
13
+
-- main.lua
14
+
15
+
local ScreenManager = require('lib/ScreenManager');
16
+
17
+
function love.load()
18
+
local screens = {
19
+
main = require('src/screens/MainScreen');
20
+
};
21
+
22
+
ScreenManager.init(screens, 'main');
23
+
end
24
+
25
+
function love.draw()
26
+
ScreenManager.draw();
27
+
end
28
+
29
+
function love.update(dt)
30
+
ScreenManager.update(dt);
31
+
end
32
+
```
33
+
Note how MainScreen inherits from Screen.lua. This isn't mandatory, but recommended since Screen.lua already has templates for most of the callback functions.
34
+
35
+
```
36
+
#!lua
37
+
-- MainScreen.lua
38
+
39
+
local Screen = require('lib/Screen');
40
+
41
+
local MainScreen = {};
42
+
43
+
function MainScreen.new()
44
+
local self = Screen.new();
45
+
46
+
local x, y, w, h = 20, 20, 40, 20;
47
+
48
+
function self:draw()
49
+
love.graphics.rectangle('fill', x, y, w, h);
50
+
end
51
+
52
+
function self:update(dt)
53
+
w = w + 2;
54
+
h = h + 1;
55
+
end
56
+
57
+
return self;
58
+
end
59
+
60
+
return MainScreen;
61
+
```
62
+
63
+
## License
64
+
65
+
Copyright (c) 2014 - 2015 Robert Machmer
66
+
67
+
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
68
+
69
+
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
70
+
71
+
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
72
+
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
73
+
3. This notice may not be removed or altered from any source distribution.
0 commit comments