Part 1: Install, Configure, Launch

Mikhail Adamenko
7 min readApr 14, 2018

--

In the previous part of the tutorial, I described what framework LÖVE is. In this part, we will go through the installation, configuration, and launching our first window of nothingness. Also, I will mention two important files to have main.lua and less important conf.lua, as well as standard functions load, update and draw.

The configuration for the framework I will show for Linux version, other parts of the tutorial will be work in every system as well, but I should say that installing process is simple enough.

Installation

The first what we need to do is … right! Download the framework, to do so, go to the main page and in the Download section find the link suitable for you, at the moment of writing the article the last version of the framework is 11.0.

If you, as I use a Debian-based Linux than you can use PPA, to get the latest version of the framework, and in the future receive updates through the update system. For PPA usage you need in terminal write commands below:

sudo add-apt-repository ppa:bartbes/love-stablesudo apt-get updatesudo apt-get install love

The commands above will install the LÖVE framework into your system globally, which is everything you need to do for writing a game.

To check if everything properly installed, you can launch default LÖVE application by writing in the terminal:

love

The result of the command should look like this:

Which is the default application of the framework, each minor version has its unique animation as well as the name, for version 11.0 it is Mysterious Mysteries.

If you want just to check a version then write the command:

love -version

The command displays current version in the terminal.

If you have the window above then installation is done, you can safely move to the next part of the tutorial.

Launching

Now, when we have the framework installed next what we will do is configuring our environment where we will be working for the rest of the tutorials.

Naming for all the objects including files, folders, functions, classes in this tutorial and the future will be provided as I use them, in my environment, you can safely use your own unless it’s mentioned to use provided.

  1. Create and name a folder anywhere you like for your game, I created a folder: GOF (Game of Life) inside a love folder in the home directory:
~/love/GOF

2. Inside the folder create the file: main.lua

*Be aware! This file is important to have, because LÖVE will be needed it, as an entry point to your game.

3. Create second file: conf.lua which will contain configurations for the game.

*The file is not required.

The file main.lua is the main file from which our game started, the file can have any functions and variables you like, but it’s also important to have these 3 functions load, update and draw, although the function have already defined in the source of the framework, so you can launch an application right now, if all you want is an ‘Untitled’ black screen.

In order to launch an application, in the terminal write love followed by the folder where file main.lua is placed. For me it will be:

love GOF

If you want to launch an application from every place, then include the full path to the folder, which in my situation:

love ~/love/GOF

here second love is the name of the folder.

load

After we launched our empty application, we can start to set it up and to do so we start with the first important load the syntax of the function:

function love.load()
— the body of the function
— btw, this is the comment line
end

What load function do? It initialized objects inside it only once at the start of the program. Thus, the function is perfectly fit for defining variables both local and global, images, fonts, shaders, and other objects.

In order to show the function at work, we give our window a name, by writing in the body method window.setTitle:

love.window.setTitle(“Game of Life!”)

This will set name for the window to Game of Life! you can launch and see the result.

update

Next function after load is update with the following definition:

function love.update(dt)
— body of the function
— function update all its
— content every frame or delta time (dt)
end

The update function useful when you want to do some action every frame, for example, increase the counter by 1 every second. To do so, you need to initialize a variable that holds value outside the function in the load or out of all functions:

dtotal = 0 — this keeps track of how much time has passed

In the Lua all variable by default is global. Then in the function keep adding delta time (dt) to the variable dtotal:

dtotal = dtotal + dt

which is the small value around 0.01, you can check it by yourself just printing the value of dt in the function to the terminal:

function love.update(dt)
print(“value of the dt: “, dt)
end

After the increase of our variable, we need to check when the value will be equal to 1 second:

if dtotal >= 1 then
-- return to the original
-- if we want to do it in the loop
dtotal = dtotal — 1 -- do some action every second
print(“a second has passed”)
end

I should mention that this is not the best implementation of the timer, because it depends on delta-time which can be rewritten and cause total chaos, but as the example, it does its job.

draw

The third function is the draw, used in the framework to draw on the screen every frame. objects like Images, Canvases, Particles, Meshes, Texts should be in this function, outside of the draw function, they will not be displayed on the screen, although still work!

But if you want to have the drawable object be outside the function, you can put them inside a Canvas and call from the draw function, which I will explain in the future tutorials.

For now, I will show how works the draw function on the example of FPS counter, which is useful in the development process to know how well games go. So, let’s write our FPS counter by using standard framework counter function.

First, we need to change the color of the displayed text from the default black to white so we can see it on the screen. All color changes happened only with this one method graphics.setColor(), inside the draw function write:

love.graphics.setColor(1, 1, 1, 1)

This will set all preceding graphics element to be a white color. The method setColor() used range from 0 to 1 in the following order (red, green, blue, alpha), so if you want to have colors other than black (0) or white (1) you can get simple RGB value and divide each color by 255, to have exact color.

Next, after we change our color, let’s print the counter to the screen by using method graphics.print() with timer.getFPS() which return current fps in number value:

love.graphics.print(“Current FPS: “..tostring(love.timer.getFPS()), 10, 10)

The 1st argument in graphics.print() method is a string: “Current FPS: ”..tostring(love.timer.getFPS()) two dots in the Lua connect the first line with the following in our case converted from number to string method .getFPS()

The 2nd and 3rd arguments are position x, y on the screen in px.

Coordinate of the LÖVE

In result, we get our FPS counter in the top-left corner.

Briefly mention configuration file, there you can change values of width, height, name, or display modes of the window, as well as to turn on or off modules, the default options and their values you can find here.

The framework has its own methods for each option in the file, so you can call and change it. Which means that the file isn’t necessary to have, but useful if you don’t want to make a mess in the code.

Outro

For now, this is it, we installed the framework, created the environment and launched the application! Next, we will start to configure our application for making Conway’s Game of Life, explanation of it and a few useful Lua libraries which will help us in the developing process.

main.lua written in the tutorial and conf.lua with default parameters of the version 11.0.

TL;DR

First, we download and install the framework, then set up an environment, in the end, simple explanation of three main functions: load, update and draw.

Before you move next

I want to thank you for reading the article, hope you find it interested to read, if not or you have something to say, please leave a comment or write directly to me. I will highly appreciate every feedback you have.

Have a good day!

--

--

Mikhail Adamenko

Born and live in Kazakhstan, Almaty, a self-taught developer, have an interest in many things from design to programming and philosophy.