How do I create a save game feature in love2d?

这一生的挚爱 提交于 2020-07-15 05:52:41

问题


I am new to game development but I need to know if it is possible to create a save game feature in love2d with lua.


回答1:


Sure. You can use a variety of libraries available. My current recommendation is Ser Binser (Ser has been deprecated). This process is called "table serialization." Then, you can do something like this to effectively create a "save."

local ser = require 'Path.to.ser'
local save 

function love.load()
    if love.filesystem.exists( 'Save.lua' ) then
        save = love.filesystem.load( 'Save.lua' )
    else
        save = {} -- Put settings in here.
    end
end
-- etc. etc.
function love.quit()
   love.filesystem.write( 'Save.lua', save )
end


来源:https://stackoverflow.com/questions/26232628/how-do-i-create-a-save-game-feature-in-love2d

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!