Hi,
How to work with multiple pictures without copy paste a code?
example:
picture1=love.graphics.newImage( filename1, settings )
picture2=love.graphics.newImage( filename2, settings )
picture3=love.graphics.newImage( filename3, settings )
In my code I want to call picture"Number1" and after picture"Number2" ... Without to create a code like this:
if picture1 then
else if picture2 then...
----Reedit----------------------
I have find a way by putting these pictures in a array but I want to free memory usage for not have double picture loaded. If you have the way to unload picture this is welcome.
Thanks
How to work with multiple pictures and variables name?
Re: How to work with multiple pictures and variables name?
Code: Select all
local filenames = {"abc.png", "def.png"} -- list of file names
local settings = {} -- your settings
local pictures = {} -- empty table
for i, filename in ipairs (filenames ) do -- iterator
local picture = love.graphics.newImage( filename, settings ) -- new picture
teble.insert (pictures, picture) -- insertion new picture to the pictures table
end
Code: Select all
_G[filename] = picture
Re: How to work with multiple pictures and variables name?
Hi,thanks
yes I think the table pictures must be global but filenames, settings can be local. I will test it.
-----------------------------------
That's work with a global table for pictures.
Thanks.
yes I think the table pictures must be global but filenames, settings can be local. I will test it.
-----------------------------------
That's work with a global table for pictures.
Thanks.
Who is online
Users browsing this forum: No registered users and 4 guests