目前,我正在使用LUA和love2d框架进行一个小游戏项目。使用这个框架,我创建了自己的资产(即按钮图像、表单图像等),并且使用这些资产我已经能够制作一个功能应用程序,但还不是一个游戏。在我的项目中,我计划有几个场景,我不太确定我的场景管理/切换方法是否有效/安全地使用(安全,就像最小的bug)。因此,我使用的过程如下:
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
其中scene_selector是指向以下文件的链接:
-- 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
sceneSplash/sceneMainMenu是指向充当场景的lua文件的链接。每个文件管理自己的更新,这些更新由main.lua
传递--由love.update和love.draw函数找到,这些函数被传递到相关的加载/更新/绘制函数中。我的目标是使用大约10个表单,3个变量文件和2个misc函数文件(文件管理/加密/IO操作/日志记录/等等)。
所以TL;DR版本是-它是有效的/安全的(在最小的bug方面)通过绘制和更新函数从main.lua到其他lua脚本文件?
到目前为止,这个过程没有任何bug,即使我回到以前访问过的“场景”,所以我假设当我使用更多的场景时,这个过程将“安全地”工作。
发布于 2016-01-08 15:21:59
为了回答您的问题,让其他函数(可能在其他文件中)更新或绘制它们负责的部分(或者如果您愿意的话)是非常安全和常见的。要记住的重要一点是,将东西绘制到love.draw()
函数之外的屏幕上,或者从该函数中调用的函数都不会产生任何效果,因为在调用main.lua
脚本中的love.draw()
之前,屏幕是被清除的。
现在,关于效率的问题;所有函数调用都有最小的开销。与Lua中的任何其他函数调用相比,从love.update()
或love.draw()
调用函数不会产生任何额外的开销。
发布于 2015-11-23 23:48:56
我也在和love2d“玩”。
如果.你可以省点钱。如果你用这样的普通场景:
if currentScene.loaded == false then
currentScene.link.load()
currentScene.link.update(dt)
currentScene.link.draw()
currentScene.loaded = true
else
currentScene.link.update(dt)
end
不断变化的场景:
currentScene.unload() --if you need to releas resurces.. invoce gc .. ecc
currentScene= sceneMainmenu
currentScene.loaded = false
https://gamedev.stackexchange.com/questions/111857
复制