Help For starting

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:

The docs contain all the info you’ll need

1 Like

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()

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) :man_shrugging:

You can read to understand how to manage image banks (called imagesheet in Solar2D)

and to blit one single image of an imagesheet.

Hope it could help !

1 Like

Thank you!

1 Like