Question on using arrays for images and buttons

Hello,

In one app I wrote I use an array for different sets of images so I do not exceed the 200 max limit. I am using the arrays like imgPerson[i].x and works great.

Now I am working on another app and 90% of the app is in one scene and I have a lot of images and buttons. So I decided to use arrays again but with this app each image and button are different meaning they are not in a set. So if I use a number for each array I will not know what image it is by looking at the code unless I comment by each or look it up. Can I use words instead? Something like imgButton[“capture”] or something similar to this?

I just looked it up again and found the docs on tables that I missed and it shows using t[“x”] in there. So can I do the following and with t as the array does this count for only 1 out of the 200 limit?

Thanks,

Warren

local t = {} t["image1"] = display.newImageRect( "images/header.png", Width7, 77 ) t["image1"].anchorX = 0.5 t["image1"].anchorY = 0 t["image1"].x = 320 t["image1"].y = 0 t["image2"] = display.newImageRect( "images/logo.png", 500, 77 ) t["image2"].anchorX = 0.5 t["image2"].anchorY = 0 t["image2"].x = 320 t["image2"].y = 100

yes:   t.x is just a shortcut way of writing t[“x”] – they are equivalent

(humans prefer to write the former, but internally Lua always does the latter)

Is the 200 limit a requirement of your game?  Just asking in case there was confusion about actual image limits.

The only thing I know of that has a limit is locals.  You can have 200 locals per file-level visibility (and I may have that slightly wrong).

-Ed

I was worried about going over the 200 limit for variables but using the tables will fix that issue.

Is there an image limit? I don’t think I will go past that or at least size of graphics because I am removing some graphics and adding new ones in when the character changes.

I’m not much into writing games but I couldn’t pass on this one so I’m learning as I go…

Thanks!

Ahh,

A. No limit on images, except memory and eventual FPS impact of having too many (but this is a huge number)

B. No limit on entries in tables.

Questions:

  1. Do you need to reference specific objects by number later?  OR, are you simply identifying an objects after a collision or touch and then wanting to find it in the array?

  2. Are you adding and removing images from this array dynamically?  I think the answer is yes, but I want to check.

There is no collision or physics used in this game. I have an almost transparent image over the play area that I am detecting multitouch taps to make a character run. I am swapping images for the character rather than using an image sheet which is working well.

All of the other images I am using a table and naming them like images[“background1”] so I can recognize what they are throughout the code. I am adding images at the start of the app using the table for it. I’m not using the table for images I am removing and adding dynamically. I just have a character running in place and then other images for background and then menu screens that popup and go away. I inserted the images in different display groups for each menu so I can use transition.to to show and hide them.

yes:   t.x is just a shortcut way of writing t[“x”] – they are equivalent

(humans prefer to write the former, but internally Lua always does the latter)

Is the 200 limit a requirement of your game?  Just asking in case there was confusion about actual image limits.

The only thing I know of that has a limit is locals.  You can have 200 locals per file-level visibility (and I may have that slightly wrong).

-Ed

I was worried about going over the 200 limit for variables but using the tables will fix that issue.

Is there an image limit? I don’t think I will go past that or at least size of graphics because I am removing some graphics and adding new ones in when the character changes.

I’m not much into writing games but I couldn’t pass on this one so I’m learning as I go…

Thanks!

Ahh,

A. No limit on images, except memory and eventual FPS impact of having too many (but this is a huge number)

B. No limit on entries in tables.

Questions:

  1. Do you need to reference specific objects by number later?  OR, are you simply identifying an objects after a collision or touch and then wanting to find it in the array?

  2. Are you adding and removing images from this array dynamically?  I think the answer is yes, but I want to check.

There is no collision or physics used in this game. I have an almost transparent image over the play area that I am detecting multitouch taps to make a character run. I am swapping images for the character rather than using an image sheet which is working well.

All of the other images I am using a table and naming them like images[“background1”] so I can recognize what they are throughout the code. I am adding images at the start of the app using the table for it. I’m not using the table for images I am removing and adding dynamically. I just have a character running in place and then other images for background and then menu screens that popup and go away. I inserted the images in different display groups for each menu so I can use transition.to to show and hide them.