LÖVE Game Development Fundamentals
Setting Up LÖVE
Get LÖVE on Your Machine
First, you need to download LÖVE. Go to the official website, love2d.org, and grab the version for your operating system. It's a free, open-source framework for making 2D games in the Lua programming language.
After downloading, you'll need to install it and make sure you can run it from your command line or terminal. This process, called adding to your PATH, lets you type love anywhere to run your game.
| Operating System | Installation Steps |
|---|---|
| Windows | Run the installer. During installation, make sure to check the box that says "Add LÖVE to the PATH." This makes running games much easier. |
| macOS | Unzip the downloaded file and drag love.app to your Applications folder. You'll need to manually add it to your PATH. Open Terminal and run: sudo ln -s /Applications/love.app/Contents/MacOS/love /usr/local/bin/love |
| Linux | Use your distribution's package manager. For example, on Ubuntu or Debian, you'd run sudo apt-get install love. On Arch Linux, it's sudo pacman -S love. |
Set Up Your Code Editor
You can write code in any plain text editor, but a dedicated code editor makes life much easier. We recommend Visual Studio Code (VS Code). It's free, runs on all major operating systems, and has a huge library of extensions to add new features.
Download it from code.visualstudio.com and install it.
To make VS Code work well with Lua and LÖVE, you should install a couple of extensions. Extensions add features like syntax highlighting (which colors your code to make it easier to read) and code completion (which suggests code as you type).
Open VS Code, click the Extensions icon on the left-hand sidebar (it looks like a set of blocks), and search for and install these two extensions:
- Lua by sumneko: This provides excellent language support for Lua.
- LÖVE 2D Support by pixel-byte: This adds code snippets and autocompletion for LÖVE's specific functions.
Your First LÖVE Project
A LÖVE game is incredibly simple at its core. It's just a folder that contains a file named main.lua. That's it.
First, create a new folder somewhere on your computer. Let's call it hello-love. Inside that folder, create a new file and name it main.lua.
Now, open the hello-love folder in VS Code. Open the main.lua file and add the following code. This program will create a window and display the text "Hello, World!" on the screen.
function love.draw()
love.graphics.print("Hello, World!", 400, 300)
end
The love.draw() function is one of LÖVE's special "callback" functions. LÖVE automatically calls this function about 60 times every second. Anything you want to appear on the screen should be put inside it.
Here, love.graphics.print() is the function that draws text. The first part, "Hello, World!", is the text to draw. The numbers 400 and 300 are the coordinates on the screen where the text will appear, measured in pixels from the top-left corner.
To run your game, open your system's terminal or command prompt. Navigate to your
hello-lovefolder using thecdcommand (e.g.,cd Documents/hello-love).Once you are inside the folder, simply type the following command and press Enter:
love .The
.is important—it tells LÖVE to run the project in the current directory.
If everything is set up correctly, a window should appear with your message. You've just created and run your first LÖVE game.
