Drawing an image
In this tutorial we will draw this whale.
Create an assets
folder in the same directory as your main.lua
. Then right click the image to save it in your assets folder. This way we keep scripts and assets nicely separated.
Note
It is not mandatory to put your images in a folder. You can place your files wherever you like, as long as they are somewhere in your project folder.
To draw the image, we first need to load it. We do this with love.graphics.newImage(image)
.
local image
function love.load()
image = love.graphics.newImage("assets/whale.png")
end
The variable image
is now our Image
object.
We can draw the image with love.graphics.draw(image, x, y)
.
local image
function love.load()
image = love.graphics.newImage("assets/whale.png")
end
function love.draw()
-- Draw the image on position 100, 100
love.graphics.draw(image, 100, 100)
end
Whale done! ;)
Bonus challenge #
Make the whale move back and forth!