I would like to make a table of variables that contain images.
Then, whenever I need them, I can access them and display them from the table instead of creating multiple display.newImage things.
Is this possible?? how so, please help!
I would like to make a table of variables that contain images.
Then, whenever I need them, I can access them and display them from the table instead of creating multiple display.newImage things.
Is this possible?? how so, please help!
I’m not entirely sure I understand your question, because ultimately if you want to see an image on screen you need to create a newImage or newImageRect object.
If you want to add images to a table before hand then just create the image and add it to a table:
local myTable = {} myTable[#myTable+1] = display.newImage("myImage.png") myTable["favourite"] = display.newImage("myFavouriteImage.png") --etc
The thing is, all these images would appear on screen, and you would need to hide them. This also means that you potentially have images on screen which may never end up being used, wasting memory.
The easiest way to do this, I have found is to use 2 things. First, you write a little script to dump table contents.
Util.xmp = function(o, depth) if depth == nil then depth = 1 end if type(o) == 'table' then local s = '{ ' depth = depth-1 if depth \>= 0 then for k,v in pairs(o) do if type(k) ~= 'number' then k = '"'..k..'"' end s = s .. '['..k..'] = ' .. util.xmp(v,depth) .. ',' end else s = s..'?' end return s .. '} ' else return tostring(o) end end
Second, a program called “_activate” from http://j-strahan.com/main/?p=262, which I bought. Look at the usage below.
local activate = require( “_activate” )
print = activate.gameLog() – this is the magic. You override the print function to display to the _activate window.
Now you do print(Util.xmp(mytable)) and you have dumped a table to the screen at runtime. Works on my Android and an iPhone without trouble.
If you want to have one display object with many different images, you need to look into Sprites. It’s what they are used for. If you want something more like a deck of cards, where you have all 52 card faces and a card back and want to be able to quickly swap them out, then you can use a table to hold each separate display.newImageRect() and then use the .isVisible property or .alpha property to control which is showing at any given moment.
I’m not entirely sure I understand your question, because ultimately if you want to see an image on screen you need to create a newImage or newImageRect object.
If you want to add images to a table before hand then just create the image and add it to a table:
local myTable = {} myTable[#myTable+1] = display.newImage("myImage.png") myTable["favourite"] = display.newImage("myFavouriteImage.png") --etc
The thing is, all these images would appear on screen, and you would need to hide them. This also means that you potentially have images on screen which may never end up being used, wasting memory.
The easiest way to do this, I have found is to use 2 things. First, you write a little script to dump table contents.
Util.xmp = function(o, depth) if depth == nil then depth = 1 end if type(o) == 'table' then local s = '{ ' depth = depth-1 if depth \>= 0 then for k,v in pairs(o) do if type(k) ~= 'number' then k = '"'..k..'"' end s = s .. '['..k..'] = ' .. util.xmp(v,depth) .. ',' end else s = s..'?' end return s .. '} ' else return tostring(o) end end
Second, a program called “_activate” from http://j-strahan.com/main/?p=262, which I bought. Look at the usage below.
local activate = require( “_activate” )
print = activate.gameLog() – this is the magic. You override the print function to display to the _activate window.
Now you do print(Util.xmp(mytable)) and you have dumped a table to the screen at runtime. Works on my Android and an iPhone without trouble.
If you want to have one display object with many different images, you need to look into Sprites. It’s what they are used for. If you want something more like a deck of cards, where you have all 52 card faces and a card back and want to be able to quickly swap them out, then you can use a table to hold each separate display.newImageRect() and then use the .isVisible property or .alpha property to control which is showing at any given moment.
Hi guys, sorry to interrupt…
But I think I have the same problem than isiah…
If you got it
Could you please post a sample code here so I can see it. I have the idea of isVisible or .alpha but I don’t really know how to apply it.
Hi guys, sorry to interrupt…
But I think I have the same problem than isiah…
If you got it
Could you please post a sample code here so I can see it. I have the idea of isVisible or .alpha but I don’t really know how to apply it.