Love - Drawing an Image

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

Requirements

You need to have followed the installation process for the Love engine.

You also need to have created a minimal game (ie a new folder, with a 'main.lua' file)

You need to have added this code to 'main.lua':

function love.load()

end

function love.update(dt)

end
 
function love.draw()

end

Load the Image

Firstly in the love.load, we should add the following code to load in an Image:

image=love.graphics.newImage("test.png")

This image ie 'test.png' should be in your game folder, in the same location as 'main.lua'. PNG would be the best format to use because it supports alpha transparency (ie every pixel can have a transparency between 0 & 255).

Draw the Image

Now in the love.draw method, add the following to draw the image:

love.graphics.draw(image, 100, 100) -- 100, 100 is the X & Y position of the image