跳转至内容

09. Save&Load,Camera,Canvas

3.5,继续教程。

Save&Load

简化的保存和加载。

lua
function saveGame()
    serialized = lume.serialize(data)
    love.filesystem.write("savedata.txt", serialized)
end
lua
if love.filesystem.getInfo("savedata.txt") then
    file = love.filesystem.read("savedata.txt")
    data = lume.deserialize(file)
end
https://github.com/rxi/lume

Camera

简化的摄影机,让整个画面以玩家为中心移动。

lua
function love.draw()
    love.graphics.push()
    -- 世界坐标整体平移,玩家位置移动到屏幕中心 (400, 300)
    love.graphics.translate(-player.x + 400, -player.y + 300)
    -- ...
    love.graphics.pop()
end