LÖVE is a fantastic framework that leverages the Lua scripting language for developing 2D games; it is open source, free to use, and licensed under
zlib/libpng. You can learn more about Lua programming at www.lua.org.
In this chapter we'll go through the following:
All we need to get started with LÖVE
How to install LÖVE
How to run a LÖVE game
Choosing the editors
And a step further to understand the basic structure that makes a LÖVE game.
Direct your web browser to www.love2d.org, scroll to the download section of the site and choose the installer that is compatible with your computer.
It is advisable that we download an installer instead of the source codes, except for when we want to be geeky and build it ourselves.
Linux users are required to download the
.deb install file by clicking on build number of their operating system; users running Precise Pangolin Ubuntu OS should click on the 12.04 link. Run the install program and follow the instructions. If the LÖVE framework is fully installed, you can double-click on a .
love file to run it.
Mac users should visit the LÖVE wiki (https://www.love2d.org/wiki/Getting_Started) page for instructions on how to install LÖVE and run a packaged game.
--create a display function love.draw() --display a text on a 800 by 600 screen in the positions x= 400, and --y=300 love.graphics.print('hello world!', 400, 300) end
Now save this code as
main.lua. Open a folder for your game project, put your
main.lua file inside the folder, and compress the content of the folder. Change the
.zip extension to
.love. You'll notice a change in the icon of the compressed file; it changes to a LÖVE logo. Now that we've done all that, we can run our game. If you follow the instructions correctly, you should see a screen similar to the following screenshot:
If you do not compress the file properly, you will get the following blue screen displaying error information:
--load our assets function love.load() --load all assets here end --update event function love.update(dt) --do the maths end --draw display function love.draw() --describe how you want/what to draw. end
That's just it, well... maybe! So let's play with these chunks one more time.
function love.load() local myfont = love.graphics.newFont(45) love.graphics.setFont(myfont) love.graphics.setColor(0,0,0,225) love.graphics.setBackgroundColor(255,153,0) end function love.update() end function love.draw() love.graphics.print('Hello World!', 200, 200) end
Before you go on and start coding your game, you need to give your video game some specs such as window width, window height, and window title. So set up a new file named
conf.lua; inside it you can then create your game specs as shown in the following code snippet:
function love.conf(w) w.screen.width = 1024 w.screen.height = 768 w.screen.title = "Goofy's Adventure" end
You can manipulate the figures and titles any way and also change that
w to whatever variable you want.
The preceding code does the following:
Loads our font
Sets the font color
Sets the background color
Draws text on the screen
Configures the screen size
Basically we are using the
love.graphics module; it can be used to draw (in the real sense) texts, images, and any drawable object in the scene. In the previous code snippets, we defined our fonts with the
love.graphics.newFont(45) that formats our text by declaring the size of the font as
setFont() loads the font we defined as
setColor() colors the text in the RGB format, and
setBackgroundColor() sets the background.
Then we printed text using the
love.graphics.print('text', x, y) function in the
draw function with three parameters parsed in it: the text and the x and y coordinates. We are not going to do anything in the
love.update() function yet, because we are not dealing with scene events.
Now we can grab a mug of cappuccino with Ray-Bans on and smile; we have installed the LÖVE game engine, text editor, and Visual tile-level editor (Tiled). We have also got a quick look at the basic structure for writing our game in Lua and displayed "Hello World!" in a colored background window. Next we'll go through how to draw 2D objects, move objects, and animate character sprites.