Hi, I ran into a problem while creating a game. I created a table with icons. And I would like to display the icon on the screen. How can you do this?
You should probably take a look at some demo projects and how they were made: https://docs.coronalabs.com/guide/programming/index.html
The docs contain all the info you’ll need
What does it means ?
Can you put the code you used to do that ?
I apologize for the wrong question.
There is a table inside which there are names of icons
local ItemsTable = {
{ItemName = “Apple”},
{ItemName = “Screw”},
{ItemName = “Banana”},
{ItemName = “Three”}
}
I want to show icons in the function, display the names of icons
local function ShowItems ()
local newItem = display.newText()
end
Tell me how you can do this?
Hum… devex is right, you should read tutorial but I’ll try to explain you anyway.
Suppose your images are 64 * 64 pixel in size.
you must already build a single large image with your 4 icons. The image size will therefore be 256 * 64 pixels
Then you have to load it into memory
oIconBank = graphics.newImageSheet('my4icons.png', {width = 64, height = 64, numFrames = 4})
If you really want to have your table, you can do
local ItemsTable = {
Apple = 1,
Screw = 2,
Banana = 3,
Three = 4
}
And to blit the Apple Icon
local displayedIcon = display.newImageRect(oIconBank, ItemsTable.Apple, 64, 64);
displayedIcon.x = 100
displayedIcon.y = 100
It’s a bit weird, but with solar2D you have to position the sprite after creating it.
I have not test this code but it should works (maybe)
You can read https://docs.coronalabs.com/guide/media/spriteAnimation/index.html to understand how to manage image banks (called imagesheet in Solar2D)
and https://docs.coronalabs.com/api/library/display/newImageRect.html to blit one single image of an imagesheet.
Hope it could help !
Thank you!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.