Getting Started With Love2D Basics
Wednesday July 19 2017

I recently started playing around with Love2D for game development. Although I am completely new to Lua, so far it's been pretty fun and I really like it.

I created this post to write down the most important basic concepts that I have encountered so far, so that I can use as quick reference later.

Setting Up a Basic IDE

So far I've been using Love2D in Windows. Initially I started using Sublime Text 2 as my editor, but then figured out how to make my Love2D development experience much better using Atom combined with Github for Windows.

In Atom there is a great package called love-ide which has many great tools and features for developming with Love.

Some of these features include Lua linting, autocomplete, and being able to run the Love application right from Atom.

Additionally, we will want to use Window's console for debugging. To do so, enable these options:

Working With Keyboard Keys

We can interact with user input through the keyboard by determining if a certain key has been pressed. This is done like this:

iflove.keyboard.isDown("right")then-- ...end

The love.keyboard.isDown function receives a KeyConstant string argument to indicate which key we want to test for. The complete list can be found here. Here are some examples:

Key string

Description

space

Space key

backspace

Backspace key

down

Down arrow key

Movement

In a Love program, the Love function love.update() is called every tick, followed by the love.draw() function.

To make objects move in the canvas, we can simply update their coordinate values inside the update() function. Then the draw() function will re-draw with the new values:

Keep in mind that the x variable is global and can be accessed by all of the functions in the example above.

Object Oriented Programming

Lua doesn't come with built-in support for Object Oriented Programming. However, there is a very good small library called middleclass that allows us to easily create our own classes and design our games in a OOP fashion: