LÖVE
LÖVE is a framework you can use to make 2D games in Lua. It’s free, open-source, and works on Windows, macOS, Linux, Android and iOS.
Community and Links
Examples
Hello World
This is the full source for ‘hello world’ in LÖVE. Running this code will cause an 800 by 600 window to appear, and display white text on a black background:
function love.draw()
love.graphics.print('Hello World!', 400, 300)
end
Draw an Image
function love.load()
whale = love.graphics.newImage("whale.png")
end
function love.draw()
love.graphics.draw(whale, 300, 200)
end
Play a Sound
function love.load()
sound = love.audio.newSource("music.ogg", "stream")
love.audio.play(sound)
end
Functions
love.load()
This function is called at the beginning and it’s supposed to load all your data and variables.
function love.load()
hero = {}
hero.name = "Ruben"
hero.health = 100
hero.alive = true
score = 0
end
love.update
This function runs repeatedly during the session. The variable dt
is used to update your data, as it marks the time passed since it last ran.
function love.update(dt)
if hero.health < 1 then
hero.alive = false
end
if enemy.dead then
score = score + 1
end
end
love.draw
Like love.update
, this function is also called continuously, but rather than calculate the values, it draws game elements on the screen.
function love.draw()
love.graphics.print(score, 400, 300)
end
The value being printed score would constantly be redrawn, but since we are also updating the value of it in the update function, on every redraw we would get the most updated value.
Beyond the Basics
Movement
if love.keyboard.isDown("right") then
hero.x = hero.x + hero.speed * dt
end
Drawing Elements
love.graphics.rectangle("line", 400, 300, 100, 100)
Drawing an Image
love.graphics.draw("path to img", 400, 300, 100, 100)
License
LÖVE is licensed under the liberal zlib/libpng license. This means that:
- It costs nothing.
- You can use it freely for commercial purposes with no limitations.
The source can be found on GitHub.