How to make function for images?
Posted: Thu Aug 24, 2023 4:48 pm
I am new to programming. Therefore, I can't code a function that .draw images automatically when they are in the folder.
I made this function that automatically detects images and makes a direction for them( this part is working)
I got this for automatic .draw of these images, but they are showing for 1 frame and then disappear. Autoimg is in love.draw() and maker() in love.load()
Code: Select all
function maker()
AllImgFiles = love.filesystem.getDirectoryItems(dir)
local n = 1
while n <= (#AllImgFiles) do
table.insert(newdir, dir .. AllImgFiles[n])
table.insert(img, love.graphics.newImage(newdir[n]))
table.insert(imgWidth, img[n]:getWidth() +10)
n = n + 1
end
end
Code: Select all
_G.times = 1
function images(s, x, y )
for i = 1, (#AllImgFiles), 1 do
love.graphics.draw(img[times],x, y, 0, s, s, tiw[times])
times = times + 1
end
end
function autoimg(s, x, y )
if times < (#AllImgFiles) then
images(s, x, y)
end
end