How to set "setReferencePoint" for an image within a table?

Hi All,

I have a quick question on tables in Corona.

I have a table that contains images:

local images = { one="1.png", two="2.png", three="3.png", four="4.png" }  

I have built a logic that moves this images around on the screen. At certain point in time, when all the images are in their correct place, I would like to call a function.

My issue is that I can’t seem to figure out how to write code which will know that images are in their designated place and its time to call the required Function. For example, my understanding is that if I have my 1.png’s x and y location to be 10 and 0, respectively, and if I use the following code then I should be able to figure out if the 1.png is at its correct place or not. I’m using this code:

if images.one.x = 10 and images.one.y = 0 then -- certain code goes here end

but it is not working for me, which obviously concludes that I’m doing something wrong.

I thought about setting reference point of my images by using the following line of code:

images.one.x:setReferencePoint( display.TopLeftReferencePoint )  

but again its not working for me.

Can someone please point me in right direction? This is my first code and I’m planning to make it available on Corona once it is finished so other beginners can learn faster.

Please let me know if you would like to provide me additional information.

Any help would be very much appreciated!

Thanks
JP [import]uid: 82666 topic_id: 23849 reply_id: 323849[/import]

Any time you’re repositioning the reference point of a display object, you’ll want to update it’s x,y position (even if it’s the same as the current position) so that the reference point change takes effect.

More specifically, if you change the vertical part of the reference point, and then reset the y value, the object would only move up/down, no matter what change you made to the horizontal component of the reference point, and vice versa. [import]uid: 87138 topic_id: 23849 reply_id: 96054[/import]

Thanks Revaerie!

May I know how can I update reference point of an image that is stored in a table? I am not able to get the syntax correct. Can you please help me with the syntax?

Thanks in advance!

JP [import]uid: 82666 topic_id: 23849 reply_id: 96056[/import]

It’s not going to be any different than normal really, you just access the object through your table.

From the code you posted, you don’t actually have any display objects at all so I can’t really tell what you’re doing exactly, but it looks like you might have a typo here:

 images.one:setReferencePoint( display.TopLeftReferencePoint )  
 images.one.x, images.one.y = yourX, yourY  

As it stands, your table is holding strings not display objects so there is of course no reference point to set at all.

Maybe you mean to do:

[code]
local images = { display.newImage(“1.png”), display.newImage(“2.png”), display.newImage(“3.png”), display.newImage(“4.png”) }

– then access 2.png as:
images[2]:setReferencePoint…
[/code] [import]uid: 87138 topic_id: 23849 reply_id: 96059[/import]

Hi Revaerie,

Thanks for the clarification! I wasn’t even aware of the string and numeric things in Table. No wonder when I tried …print( images.one.x ) …and the system threw out a “nil” value…lol

I am too far ahead in the development that I don’t think I would be able to change the values from string to numeric…by the way I already tried changing the values from string to numeric but the images are not displaying where they were displaying when they were string…dont wanna spend additional time troubleshooting.

Would you be able to tell how I can get the location of these images after they are loaded on the screen? My main goal is to identify their location and use additional logic (if ifelse logic) to find out if they are at their correct location or no. If they are at their correct location the game moves to next level.

I am sure there is a workaround for this but after all day looking on Corona’s site and the web it seems like I am out of options.

Regards,
JP [import]uid: 82666 topic_id: 23849 reply_id: 96067[/import]

If your doing it like the post above yours suggested you could do this to find there locations

images[2].x  
images[2].y  

for instance [import]uid: 84637 topic_id: 23849 reply_id: 96082[/import]