Loading an Image
So now you've learned the basics of printing text, using a certain color on the screen. Now we'll learn how to use images. Before displaying an image we must load it. To load an image, we set a variable to it. (A variable is basically a value that we define) for example in the tutorial above, red was our variable. It defined what color is. Anyways let’s get back to coding.
To load an image in LuaDev, we set a variable and call this function. Take note the quotations are required.
image.load("location/filename.format") -- common ‘I’ is used in LuaDev
Location - To load an image, you must set up a location. If the location is in the same folder where the lua scipt is located, you can simply use the filename. Example if you want to load an image from a folder called “Images”, this is how you’d do it.
image.load("Images/filename.format")Filename – This is the name of the image you are using. For example
image.load("background.format")Format – LuaDev can load jpeg/png and gif images. These are the file formats.
This is how you load an image.
bg = image.load("Images/background.png")bg is our variable.
Displaying an Image
After loading our image we need to display it. To display our image in Luadev, you can do it in two ways.
1. By calling the variable itself:
variable:blit(x,y) – I already stated above what the ‘x’ and ‘y’ means. Look into it for reference
2. By calling “image.blit”
image.blit(x,y,variable)
bg:blit(0,0) Or image.blit(0,0,bg)
bg = image.load("Images/background.png") while true do image.blit(0,0,bg) screen.waitvblankstart() endor
bg = image.load("Images/background.png") while true do bg:blit(0,0) screen.waitvblankstart() endBoth carry out the same operation.
Written By Joel16 & Edited by Ahmed Aziz