Yet Another Screen manager
This is a scene manager for LÖVE. It allows you to easily switch between scenes and manage them. It is simplier than Scenery. Just drop-in and write your scene.
Copy yas.lua
into your directory with game and require it in love.load
.
You can see some other examples in examples/
folder.
-- main.lua
function love.load()
yas = require "yas" "folder_with_scenes"
end
-- main_scene.lua
default = true
some_var = 42
enter = function()
print "Just loaded main scene!"
end
update = function()
print "Updated main scene!"
print("some_var become", some_var)
some_var = some_var + 1
end
draw = function()
print "Drawing main scene!"
end
YAS can automatically load all scenes from folder. Just pass folder name to require
function.
yas = require "yas" "folder_with_scenes"
You can also load scenes manually.
yas = require "yas" {
{ "scene1", path = "path/to/scene1.lua", default = true},
{ key = "scene2", path = "path/to/scene2.lua"},
{ key = "scene3", path = "path/to/scene3.lua"},
}
All scenes are Lua files. They can contain any Lua code. You can define callbacks from LÖVE in scene file, that defined in LÖVE documentation, but there are some special functions that will be called by YAS.
This function will be called when scene is paused and drawing. It can be called by yas.toggle
or toggle_scene
function or when you switch to another scene.
This function will be called when scene is loaded. It can be called by yas.set
or set_scene
function or when you switch to another scene.
This function will be called when scene is unloaded. It can be called by yas.set
or set_scene
function or when you switch to another scene.
You can set default scene by setting default
variable to true
in scene file.
default = true
You can set paused scene by setting paused
variable to true
in scene file.
paused = true
This function will set scene by key.
Global alias: set_scene
.
yas.set "scene1"
-- or
yas.set("scene1", {some_var = 42})
This function will toggle current scene.
Global alias: toggle_scene
.
yas.toggle()
-- or
yas.toggle(true)
This function will return current scene key.
print(yas.current())
This function will return table with all scenes.
print(yas.scenes())
This function will return scene by key.
print(yas.get "scene1")
This function will return previous scene key.
print(yas.previous())
This function will add scene to scenes table.
yas.add("scene1", {enter = function() print "Loaded scene1!" end})
This function will remove scene from scenes table.
yas.remove "scene1"