When beginning to write games using Lutro, the most important parts of the API are the callbacks: love.load
to do one-time setup of your game, love.update
which is used to manage your game's state frame-to-frame, and love.draw
which is used to render the game state onto the screen.
More interactive games will override additional callbacks in order to handle input from the user, and other aspects of a full-featured game.
Lutro provides default placeholders for these callbacks, which you can override inside your own code by creating your own function with the same name as the callback.
love.load
is called once in the lifetime of the application, at the very beginning. Use this to load assets and initialize your game.
function love.load()
whale = love.graphics.newImage("whale.png")
x = 0
end
love.update
is called once per frame, 60 times per second. Use this to execute your game logic.
1.0/60.0
function love.update(dt)
x = x + 1
end
love.draw
is also called once per frame, 60 times per second. Use this to draw your game graphics.
function love.draw()
love.graphics.draw(whale, x, 32)
end
love.gamepadpressed
is called when a player pressed one of the joypad buttons.
function love.gamepadpressed(i, k)
print("player pressed", i, k)
end
Same as love.gamepadpressed
but called when a button is released.
This is an optional callback. When the libretro frontend calls love.serialize
, your game can return a serialized game state in the form of a string. Think of this as savestates in an emulator.
function love.serialize(size)
local gamestate = {}
gamestate.x = x
return json:encode(gamestate)
end
This is an optional callback. When the libretro frontend calls love.unserialize
, your game will receive a game state serialized as a string. Think of this as savestates in an emulator. It's up to the game developer how to implement proper unserialization.
function love.unserialize(data, size)
if data == nil then return end
local gamestate = json:decode(data)
x = gamestate.x
end
This is called when the libretro frontend wants to know the size of your game savestate. Choosing a large and constant value is fine.
function love.serializeSize()
return 1024*8
end
This is called when the libretro frontend wants to reset the game. In this callback, you can free resources and reinitialize your game to start over.
function love.reset()
gamestate = {}
love.load()
end