Menu 更改love.load函数中的内容
我和我的朋友最近一直在love2d中开发一款游戏,但在开发电脑硬盘的早期阶段,硬盘停止工作,这意味着只有我的朋友才能开发。现在我有了一台电脑,我想在Love2d中制作一个主菜单,但是love.load函数中有很多代码(生成世界等等)。我的问题是,当游戏运行时,我能改变什么是爱。加载吗?e、 g主菜单加载,然后当按下开始按钮时,世界的生成加载。love.load功能只运行一次。正如您所提到的,它通常用于设置数据结构和预加载其他资源。您可以使用它来处理世界预加载和菜单预加载。然后,通过某种状态控制什么是活动的。一个简化的例子:Menu 更改love.load函数中的内容,menu,lua,love2d,Menu,Lua,Love2d,我和我的朋友最近一直在love2d中开发一款游戏,但在开发电脑硬盘的早期阶段,硬盘停止工作,这意味着只有我的朋友才能开发。现在我有了一台电脑,我想在Love2d中制作一个主菜单,但是love.load函数中有很多代码(生成世界等等)。我的问题是,当游戏运行时,我能改变什么是爱。加载吗?e、 g主菜单加载,然后当按下开始按钮时,世界的生成加载。love.load功能只运行一次。正如您所提到的,它通常用于设置数据结构和预加载其他资源。您可以使用它来处理世界预加载和菜单预加载。然后,通过某种状态控制什
local state = "menu"
function love.load()
preLoadMenu()
preLoadWorld()
end
function love.update(dt)
if state == "menu" then
updateMenu()
else
updateWorld()
end
end
function love.draw()
if state == "menu" then
drawMenu()
else
drawWorld()
end
end
function love.mousepressed(x, y, button)
if startClicked(x,y,button) then
state = "world"
end
end
local currentScene
function love.load()
currentScene = loadMenu()
end
function love.update(dt)
currentScene.update(dt)
end
function love.draw()
currentScene.draw()
end
function love.mousepressed(x, y, button)
if startClicked(x,y,button) then
currentScene = loadWorld()
end
end
可以想象的是,你不想为你的游戏预加载任何东西。也许你的游戏太大了。如果是这样的话,考虑使用一个活跃的场景。场景可能是菜单,也可能是游戏级别。同样,一个简化的示例:
local state = "menu"
function love.load()
preLoadMenu()
preLoadWorld()
end
function love.update(dt)
if state == "menu" then
updateMenu()
else
updateWorld()
end
end
function love.draw()
if state == "menu" then
drawMenu()
else
drawWorld()
end
end
function love.mousepressed(x, y, button)
if startClicked(x,y,button) then
state = "world"
end
end
local currentScene
function love.load()
currentScene = loadMenu()
end
function love.update(dt)
currentScene.update(dt)
end
function love.draw()
currentScene.draw()
end
function love.mousepressed(x, y, button)
if startClicked(x,y,button) then
currentScene = loadWorld()
end
end
从长远来看,第二种选择更加灵活。它可以处理任意数量和类型的场景,而无需对每个场景使用条件逻辑。这需要一点“对象”思维。所有场景都需要一致的更新和绘制方式
如果您的世界需要一段时间才能加载,您可能希望显示一个临时的“世界正在加载”场景,这样您的用户就不会不耐烦了