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
Section titled “Community and Links”Examples
Section titled “Examples”Hello World
Section titled “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)endDraw an Image
Section titled “Draw an Image”function love.load() whale = love.graphics.newImage("whale.png")endfunction love.draw() love.graphics.draw(whale, 300, 200)endPlay a Sound
Section titled “Play a Sound”function love.load() sound = love.audio.newSource("music.ogg", "stream") love.audio.play(sound)endFunctions
Section titled “Functions”love.load()
Section titled “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 = 0endlove.update
Section titled “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 endendlove.draw
Section titled “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)endThe 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
Section titled “Beyond the Basics”Movement
Section titled “Movement”if love.keyboard.isDown("right") then hero.x = hero.x + hero.speed * dtendDrawing Elements
Section titled “Drawing Elements”love.graphics.rectangle("line", 400, 300, 100, 100)Drawing an Image
Section titled “Drawing an Image”love.graphics.draw("path to img", 400, 300, 100, 100)License
Section titled “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.