At the moment, I'm working on a small game project using LUA and the love2d framework. Using this framework, I've made my own assets (i.e. button images, form images, etc), and using these assets I've been able to make a functional application, but not yet a game. In my project, I plan on having several scenes, and I'm not quite sure whether my method for scene management/switching is efficient/safe to use (safe, as in minimal bugs). So the process I'm using is as follows:
if scene_selector.active_scene == "splash" then
if sceneSplash.loaded == false then
sceneSplash.link.load()
sceneSplash.link.update(dt)
sceneSplash.link.draw()
sceneSplash.loaded = true
else
sceneSplash.link.update(dt)
end
elseif scene_selector.active_scene == "menu" then
if sceneMainmenu.loaded == false then
sceneMainmenu.link.load()
sceneMainmenu.link.update(dt)
sceneMainmenu.link.draw()
sceneMainmenu.loaded = true
else
sceneMainmenu.link.update(dt)
end
end
where scene_selector is a link to the follow file:
-- Misc Vars
active_scene = "splash"
version = nil
-- Resources
cre = nil
xp = nil
-- End Vars
-- Global Script Indicator
calls = {}
calls.active_scene = active_scene
calls.version = version
return calls
and sceneSplash/sceneMainMenu are links to lua files which act as the scenes. Each file manages its own updates, which are passed through by the main.lua
- found by the love.update and love.draw functions which are passed through to the forms relevant load/update/draw functions. I'm aiming at using about 10 forms, 3 variable files and 2 misc function files (file management/encryption/IO operations/logging/etc).
So the TL;DR version is - is it efficient/safe (safe in terms of minimal bugs) to pass through draw and update functions from main.lua to other lua script files?
So far, the process works without any bugs, even when I go back to a previously accessed 'scene', so I assume the process will work 'safely' when I'm using more scenes.