Default callbacks - Doge2Dev/LitiumVM GitHub Wiki
Callbacks
Callbacks are functions that are called on the main script file.
start()
This function is called only at the beginning of the game.
function start()
initVar = 0
initTable = {1,1,1}
print("this is will only be displayed on the start of the game!")
end
render()
This function is used to render on screen
function render()
litgraphics.newText("this is a hello world", 120, 120, 8, 3, 1)
end
Also this function can be used with start()
to define the sprites at beginning of the game and draw then to screen:
function start()
-- create a sprite table --
sprite = {
{1,3,1},
{3,1,3},
{1,3,1},
}
end
function render()
-- render the sprite to the screen --
litgraphics.newSprite(sprite, 90, 90, 5)
end
update(dt)
This function is called every frame and updates the game state.
function update(dt)
i = i + 1 -- increment this variable every frame
print(i) -- print the current value of "i"
end
This function also works with the other two:
function start()
-- create a sprite table --
sprite = {
{1,3,1},
{3,1,3},
{1,3,1},
}
x = 90 -- set the x pos to 90 --
end
function render()
-- render the sprite to the screen --
litgraphics.newSprite(sprite, x, 90, 5)
end
function update()
-- update x variable every time, this means the sprite will move --
x = x + 3
end
keydown(k)
This function is called when a key is pressed.
function keydown(k)
-- if key 1 is pressed, it will print on console
if k == "1" then
print("Key down!")
end
end
keydown(k)
This function is called when a key is released.
function keydown(k)
-- if key 1 is released, it will print on console
if k == "1" then
print("Key up!")
end
end